tags:

views:

45

answers:

2

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?

+1  A: 

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.

Cristian
A: 

Hello All,

I have done similar to what Cristian suggested. But i want something else from listview as mentioned below:


private static ArrayList arrIsItemSelected= new ArrayList();

OnItemClickListener
{
boolean bCurState = chkbox.isChecked();
arrIsItemSelected.set(position, !bCurState);
}

Button b = (Button)findViewById(R.id.addbtn);
b.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) 
{
for (int i=0; i(less than)listsize;i++)
{
if (arrIsItemSelected.get(i) == true)
{
// get content of text view
// how to do this as i don't have view here
}
}

How to get listview size and content of text from text view?

Thanks JRC

JRC
@JRC this is not a forum. I know you may be used to a normal forum thread where everything is like a conversation. However, stackoverflow.com is a Question/Answers site, so you better update your question instead of *adding an answer*. Or, you can add comments.
Cristian