user2955394
user2955394

Reputation: 1183

Listview itemclick not work

  1. I have a ListView in my ListView show ImageButton.

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

  3. I set ListView.OnItemClickListner. When I run my project It's show my ListView.

  4. But When I click on Listview It's not working.

  5. Then I remove ImageButton in layout and run my project again when i click ListView It' work

  6. What wrong ?

Upvotes: 18

Views: 15568

Answers (5)

varotariya vajsi
varotariya vajsi

Reputation: 4041

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.

Upvotes: 3

Md. Arafat Al Mahmud
Md. Arafat Al Mahmud

Reputation: 3214

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.

Upvotes: 8

khurram
khurram

Reputation: 1362

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

Upvotes: 1

Venkatesh S
Venkatesh S

Reputation: 5494

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.

Upvotes: 0

saiful103a
saiful103a

Reputation: 1129

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?

Upvotes: 1

Related Questions