Listview itemclick not work

后端 未结 6 1489
深忆病人
深忆病人 2020-11-27 20:33
  1. I have a ListView in my ListView show ImageButton.

  2. I set focusalble \"false\" and focusableInTouchMode \"false\" to ImageButton.

  3. I s

相关标签:
6条回答
  • 2020-11-27 20:38

    Actually nothing is wrong. What you are doing is ok. But i think you forgot one key factor here ImageButton has it's own OnClickListener. So when you embed your ImageButton into the listview row ListView.OnItemClickListner is not working because the click/touch is invoked by ImageButton, it's because of that ListView is not getting your click/touch event. Checkout this link: How to fire onListItemClick in Listactivity with buttons in list?

    0 讨论(0)
  • 2020-11-27 20:40
    android:focusable="false"
    android:focusableInTouchMode="false"
    

    doesn't work for ImageButton.

    In your layout xml, add this property to root layout

    android:descendantFocusability="blocksDescendants" 
    

    It works perfectly for a listview that has ImageButton.

    0 讨论(0)
  • 2020-11-27 20:44

    May be you have written onclick listener for the image button in adapter class

    Example :

    imageButton.setOnClickListener(new OnClickListener() 
            {
                @Override
                public void onClick(View v) {
    
    
                }
            });
    

    If you set onclick listener for the listItem .It will automatically consume the action input so the list item may not be clicked.

    0 讨论(0)
  • 2020-11-27 20:51

    I guess you are using customize list view Item just try to set set focusable "false" and focusableInTouchMode "false" for all view in your custom_list_view_item.xml Don't worry about your image button if you using click listener for image Button in adapter, It will also work fine. just do focusable "false" and focusableInTouchMode "false" for all view in your custom_list_view_item.xml

    0 讨论(0)
  • 2020-11-27 20:57

    If you are using custom Listview and in the custom Listview row item list if only Textview and Imageview, you should remove android:inputType="". It cause problem of focusability.

    0 讨论(0)
  • 2020-11-27 21:02

    You are not the only sufferer :) This behavior is often considered as a bug by Android developers Have a look at this link of their conversation.

    To solve your problem- simply include android:descendantFocusability="blocksDescendants" attribute in your root layout.

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