OnItemClickListener doesn't work with ListView item containing button

后端 未结 8 1775
广开言路
广开言路 2020-12-01 17:33

I have ListView with custom Adapter which supplies View to ListView in this way:

   public View getView(i         


        
相关标签:
8条回答
  • 2020-12-01 18:12

    You can consider to write your on OnTouchEvent in your listview item and send the proper touchEvent to you child view , the button .

    0 讨论(0)
  • 2020-12-01 18:13

    I had also had the problem of a Button in my ListView. Unfortunately just setting the focus to false for all objects in my Adapter did not work for me.

    I now have a workaround.

    In your Adapter create an OnClickListener for the button (or other clickable object) if you have not already done that. In that OnClickListener you call the OnItemClickListener yourself.

    public void onClick(View v) {
        mOnItemClickListener.setOnItemClick(mListView, v, vPos, vId);
    }
    

    It does mean that you will need to give your adapter access to both the parent ListView and the OnItemClickListener.

    0 讨论(0)
  • 2020-12-01 18:14

    If you have ImageButtons inside the list item, you need to add:

    android:descendantFocusability="blocksDescendants"
    

    to the root list item element [such as the root layout].

    Then within each ImageButton in the list item, you need to add:

    android:focusableInTouchMode="true"
    

    This worked for me - but I was using ImageButtons, not the standard button.

    0 讨论(0)
  • 2020-12-01 18:17

    Add following line to your listView

    android:choiceMode="singleChoice"
    

    or make sure to set following lines to your layout text fields

    android:focusable="false"
    android:focusableInTouchMode="false"
    android:clickable="false"
    
    0 讨论(0)
  • 2020-12-01 18:20

    If you are using ListView in Activity, ensure you have setup setOnItemClickListener()

    myListView.setOnItemClickListener(this); // if your activity implement OnItemClickListener
    
    0 讨论(0)
  • 2020-12-01 18:22

    I have also faced the same issue I have tried to set android:focusable="false" to listview but it don't work then I add this to listview item.. like in my listview item I have uesed Toggle button which was creating problem, I add android:focusable="false" to Toggle button and listview on item click listener start work again

    0 讨论(0)
提交回复
热议问题