Listview onItemClick() checkable - android

Im having a listview with items in a custom relativelayout which implements Checkable. It contains a checkbox which gets checked/uncheked via the checkable interface.
setFocusable is set to false for the Checkbox, so that I can use onItemClicked for the listview.
Now when an item is clicked the checkbox is also selected. I am getting crazy about this.
In the getView Method for my Adapter I assign an onCheckChangeListener to the checkbox.
This listener is called everytime a listitem is clicked and checks the Checkbox.
I saw questions how to select a checkable listitem onitemclick, and im getting this behaviour by default....
The Problem with this behaviour is:
The checkbox should get checked by clicking the checkbox not clicking the listitem. I start an Actionmode for the current visible Fragment when a checkbox is clicked, and i replace the current fragment when a listitem is clicked. BOTH is happening right now and that means, wrong Actionmode for wrong fragment and force close on backpress...
best regards vino

I think you have to make all other item in custom listview to setFocusable="false"

Related

Android: Identify listviewItem when checkbox of item is checked/unchecked

I got a listView with dynamically created items. Each item has a checkbox which can be checked/unchecked. When the checkbox is pressed this function is called:
public void updateClientList(View v) {
}
Now I want to change the specific item in my arraylist which is the base of the listview. But how do I know which checkbox was checked?
How can I do that? Thanks for your help!
If you only have a checkbox, you can use the OnItemClick listener that gives you position besides the view, but with this solution you have to update the checkbox manually so it doesnt consume the item click.
Another way is to use setTag(position) on the views you supply when binding.
You should consider moving on to RecyclerView.
https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html

How to get correct position of a checkbox in a scrollable listView?

I have a scrollable listview that has 2 textViews, 3 imageButtons and 1 checkBox in each row.
In the Header of the listView, I have a delete button just above the column containing all the checkboxes of the listView.
I have to perform the delete operation of objects in the listView when 2 or more checkBoxes are checked randomly by scrolling the listView and thereafter the delete button at the top is clicked.
But the problem is that i am not getting the correct poition of the checkbox that was selected. Moreover, sometimes i get the correct position but still the object to be deleted passed is wrong. Hence the entire functionality is affected maybe due to the scrolling nature of the list.
Should i take the position in the holder of the adapter class and also bind the state of the checked or unchecked checkbox with my object.
And should I use checkBox.setOnCheckedChangeListener() or deleteButton.setOnClickListener().
If i use the latter one, then how to get all the corresponding objects of the list whose checkboxes were checked before pressing the delete button?
And where should all the related code be placed..in the listAdapter class or in the activity?
Please help me find a solution to this problem..
first of all in your getView() method you should set a specific Tag to each checkBox. For example: check1.setTag(position) then you should implement both OnCheckBoxChangeListener for your checkBoxes and OnClickListener for your delete button. As you know setting of onCheckBoxChangeListner have to be in getView() method. Then you add positions of list that their checkBox is checked to the a ArrayList with the help of getTag() method of chechBoxes in onCheckedChanged() method.
Try getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {}

Android : Checkboxes and ListView

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.

Clicking on List Item also clicks the checkboxes inside item

I've a listview where each listitem has a checkbox. When I click list item, OnItemClick is called but checkbox is also clicked, that's annoying coz checbox onclick actions are triggered.
Edit:
how can I prevent checkbox from being clicked when row Item is clicked?
UPD:
Try to add to root view of the listitem layout this attribute android:descendantFocusability="blocksDescendants".
This should work

Adding a CheckBox to ListView item prevents it from being able to receive ItemClick

In the Adapter for the ListView, I return a LinearLayout, in which I add a Checkbox, a ImageView and a TextView. This basically constructs a ListView, in which each item contains a Checkbox, a ImageView and a TextView. However the strange thing is that if I don’t add the Checkbox, then ListView receives onItemClick event correctly, as long as I add the Checkbox, onItemClick of the ListView never gets fired again, as if the Checkbox eats all the OnClick event passed to ListView.
Any ideas how can I solve this? I want the user to be able to check/uncheck the Checkboxes and at the same time be able to click on these ListView items as well if they click on area for the ListView item other than the checkbox.
Set all items focusable="false"

Categories

Resources