开发者

Android: GUI: Getting items from listview

开发者 https://www.devze.com 2023-01-19 01:30 出处:网络
I am having custom listview(with image, text and check box) and a button(named Done) in my listactivity.

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 man开发者_如何学运维y list items are checked. How to do that?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号