2

I use a CheckBox in ListView. My adapter as below:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewTag viewTag;
if(convertView == null) {
convertView = myInflater.inflate(R.layout.row, null);
viewTag = new ViewTag((CheckBox)convertView.findViewById(R.id.row_check));
convertView.setTag(viewTag);
}
else {
viewTag = (ViewTag) convertView.getTag();
}
}
class ViewTag {
CheckBox cbx;
public ViewTag(CheckBox cb) {
this.cbx = cb;
}
}

First: In ListActivity, I try to click a button to set all items checked. How to do it? Second: In ListActivity, how to get the items which were checked?

brian
  • 6,802
  • 29
  • 83
  • 124
  • Checkout [this](http://stackoverflow.com/questions/7738527/getting-an-issue-while-checking-the-dynamically-generated-checkbox-through-list/7738854#7738854) thread. – Lalit Poptani Jan 05 '12 at 06:58

3 Answers3

4

There are many approaches to achieve this, simplest method is create a boolean array to keep state of each row, and set state of check from this array. To get all checked items simply check the same array item value.

jeet
  • 29,001
  • 6
  • 52
  • 53
2

Many ways to get solution to your problem. Please check this tutorial given below, it will provide more information to get solution to your problem.

ListView Example 3 – Simple Multiple Selection Checkboxes

I hope it may help you.

Yugandhar Babu
  • 10,311
  • 9
  • 42
  • 67
1

Check this. This tutorial works for me.

san
  • 1,845
  • 13
  • 23