12
votes

Interrupteur entre OnitemClick et ONIEMLONGCLICK Event of Android ListView

Je veux demander comment changer et sélectionner un seul événement sous ListView. Mon code ci-dessous fonctionne. Mais lorsque l'OnitemLongClick incendie, l'Onitemclick incendie également. Comment puis-je changer l'événement où un seul événement sera détecté:

lstResult.setOnItemClickListener(new OnItemClickListener()
        {
            @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                    long arg3) {
                // TODO Auto-generated method stub

                //showToast(arg0.getItemIdAtPosition(position) +  "");
                 String str = searchWhere(lstResult.getItemAtPosition(position) + "");
                 String word = lstResult.getItemAtPosition(position).toString();
                 showDialog(word,str);
            }

        });
        lstResult.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

            @Override
            public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
                // TODO Auto-generated method stub
                showToast(lstResult.getItemAtPosition(position) + "");
                return false;
            }

        });


0 commentaires

3 Réponses :


1
votes

Lorsque vous retournez FALSE sur votre OnImLongClickLicklistener de sorte que cela ne serait pas incendié, vous pouvez donc définir une variable booléenne pour basculer entre vos auditeurs


0 commentaires

27
votes

retour booléen true à la fin de OnitemlongClick.


1 commentaires

de la documentation: "TRUE si le rappel a consommé le long clic, faux sinon"



8
votes

Selon Documentation de OnitemLongClickListener:

retourne vrai si le rappel a consommé le long clic, faux sinon

Vous devez retourner true si le clic long est tiré.


0 commentaires