JRC
JRC

Reputation: 808

Android: GUI: Getting items from listview

I am having custom listview(with image, text and check box) and a button(named Done) in my listactivity.

I am able to check/un check check box upon list item click event by implementing listvw.setOnItemClickListener().

Now when i click Done button, I want to know how many list items are checked. How to do that?

Upvotes: 0

Views: 315

Answers (1)

Cristian
Cristian

Reputation: 200150

Why don't you track that on your setOnItemClickListener implementation? Something like this will work:

int count = 0;

public void setOnItemClickListener(args...){
    // blah blah blah
    checkbox.setChecked(!checkbox.isChecked());
    // you said: *how many*
    count += checkbox.isChecked() ? 1 : -1;
}

In the case above, you just have to use the count variable from your click listener of the Done Button. Of course, this will work fine if all the Checkboxes are unchecked when the Activity starts.

Upvotes: 1

Related Questions