Kaiusee
Kaiusee

Reputation: 55

android ListView with independent checkboxes

I have a list with checkboxes, what I need to know, is there anyway that when i click on the checkbox ONLY it will be checked and when i click on the list item i want to trigger a function but not to select the checkbox.

in other words, If I tap on any row , the check box should NOT be check unless I click on it directly.

here is my list:

listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice , items));
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

Upvotes: 0

Views: 204

Answers (2)

omermuhammed
omermuhammed

Reputation: 7385

I implemented this a while back, the thing to do is to use multiple layouts, one containing checkbox, another containing the text of the list item, and wrap it a relative layout, and add this as a row for each list item, i.e. use it to populate and create your row dynamically.

Now set an onClickListener for this list and within that block of code listen for identity of which view is getting the click and do different things.

Upvotes: 2

vancan1ty
vancan1ty

Reputation: 563

^basically what the other commenter said. I personally think the easiest thing to do would first be get your layout perfect for a single list item, then make a scrollview, put a linearlayout in the scrollview, and populate the linearlayout with the individual list items using a loop. Set onClickListeners and such in the loop, or use a single onClickListener with different tags or ids for the list items...

Upvotes: 0

Related Questions