Reputation: 1183
I have a ListView in my ListView show ImageButton.
I set focusalble "false" and focusableInTouchMode "false" to ImageButton.
I set ListView.OnItemClickListner. When I run my project It's show my ListView.
But When I click on Listview It's not working.
Then I remove ImageButton in layout and run my project again when i click ListView It' work
What wrong ?
Upvotes: 18
Views: 15568
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
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
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
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
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