Android Listview onItemLongClick监听器不能用于第二次

时间:2014-08-21 17:02:11

标签: java android android-listview

我正在android列表视图上实现LongClick Listener。这是我正在使用的代码,

this.lst_CartDetails.setLongClickable(true);

            this.lst_CartDetails.setOnItemLongClickListener(new OnItemLongClickListener()
            {

                @Override
                public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {
                    // TODO Auto-generated method stub
                    SelectedItem menu = (SelectedItem)cartdetailsAdapter.getItem(arg2);
                    if(menu.getDelete() == 0)
                    {
                        menu.setDelete(1);
                    }
                    else
                    {
                        menu.setDelete(0);
                    }
                    cartdetailsAdapter.notifyDataSetChanged();
                    //lst_CartDetails.invalidateViews();
                    return true;
                }

            });

长按是第一次使用。但是,如果我再次点击(长)该项目没有响应。

出了什么问题?

  

我发现了什么问题,OnLongClick我正在启用一个按钮   列表项。如果未启用该按钮,则longclick可以正常工作   通常

由于

3 个答案:

答案 0 :(得分:2)

如果您正在显示/隐藏捕获焦点的任何UI元素(例如:按钮),那么使其可见将在点击/长按发生时将焦点转移到该项目。为避免使用

android:focusable="false"
android:focusableInTouchMode="false"

在相应UI元素的XML布局中

答案 1 :(得分:0)

为此,通过ListView方法接收getListVIew(),并通过LongItemClickListener方法设置setOnItemLongClickListener()

  ListView list = getListView();
    list.setOnItemLongClickListener(new OnItemLongClickListener() {

      @Override
      public boolean onItemLongClick(AdapterView<?> arg0, View arg1
          int arg2 long arg3) {

        // implement the actions here
        // Return true to consume the click event. In this case the
        // onListItemClick listener is not called anymore.

        return true;
      }
    });
  }

答案 2 :(得分:0)

添加android:descendantFocusability =&#34; blocksDescendants&#34;列表视图单元解决了我的问题。

相关问题