I have a ListView containing a checkbox, an imageview, two textviews and a button. The problem is after adding the checkbox and the button the onitemclick event of the ListView is not responding. Will anybody suggest a work around for the problem?
You can set both android:focusable and android:focusableInTouchMode attributes of checkbox to false and onItemClick of the list will be called. But you'll have to call CheckBox#toggle() yourself in onItemClick.
Add an onlick listner to the view. or the checkbox and handle it manually.
When you use checkbox in your listview then it consumes your click action and your check action will be performed.
You can put click listener over textview, imageview or button. you also need to handle checkbox.
Related
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 ?
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.
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.
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?
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
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.
**I am using custom listview when i placing the button in custome view it is disabling the item touch or itemlongpress listener ...
How to use button click and listview touch simultaneously
The Problem here is , Listview having button as a child, Button will take the priority of onClick. Do the following thing
Set the property of Button to setFocusable(false);It will enable the OnClick on ListView.
For Click on Button - use onTouch instead of onClick. Which will allow you to click on button as well
try to add
android:descendantFocusability="blocksDescendants"
in the ListView tag where you define it in xml.
I got a ListView and I populate it with the view containing buttons. I set onClick listeners to the buttons from the adapted, but when I click the concrete item of the ListView - nothing happens. So, we can say only buttons onClick Listener is called, when I need listViewItem to be clicked.
What to do?
Set to your button in xml file: android:focusable="false"
This is because your Button takes focus. So now you can use both onClick for your buttons, and onItemClick for each row in ListView, by telling it that Button should not be focusable.
you need to set on item click like this listView.setOnItemClickListener();
It is better to do the onlcick on listview item only.You can set some flag and toggle between the functionalities.
I have a ListView with checkboxes in it.
When I click on a element of the ListView, it does not check/uncheck the checkbox. I want to toggle the checkbox if the user clicks on the checkbox or on the listview.
How can I do that ?
Thank you
Listen for the click event and adjust the state of the CheckBox. The onClick gives you the View that was clicked so you should be able to get the CheckBox easily.
In order to get the click listener of CheckBox in each row of list view, you can add the setOnCheckedChangeListener of checkbox in getView() method of your custom adapter.
I have an ExpandableListView which contains a list of rows with CheckBox and TextView.
I have managed get the row selectable by setting the checkbox focusable attribute to false. I have also added a OnChildClickListener to my ExpandableListView.
When i click on the TextView or any other region, the onChildClick is executed fine. But, the trouble is, when i click on the CheckBox, the onChildClick is not executed!!!
Any solutions or workaround???
Thanks
What you may want to do here is set the clickable attribute of the checkbox as false. Then, you can programmatically check and uncheck the checkbox in your code with whatever else you need to do.