+ Reply to Thread
Results 1 to 2 of 2

Thread: How to use checkbox in listview

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    15

    How to use checkbox in listview

    I use a CheckBox in ListView. My adapter as below:
    Code:
    @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?

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    14
    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.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts