Вопрос

I want to ask how to switch and select only one event under the listview. My code below is working. But when the OnItemLongClick fires, the OnItemClick also fires. How can I switch the event where only one event will be detected:

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;
            }

        });
Это было полезно?

Решение

Return boolean true at the end of OnItemLongClick.

Другие советы

According to documentation of OnItemLongClickListener:

Returns true if the callback consumed the long click, false otherwise

You should return true if long click is fired.

When you return false on your OnItemLongClickListener so this wouldn't be fire ,so you can define a boolean variable to switch between your Listeners

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top