开发者

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 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜