0

I am trying to find out the total number of selected rows in a customized list-view. If the number of items (rows) more than 2 then we cannot click the list-view again.Here I am using customized checklist(Multiple Choice)

Ann
  • 727
  • 1
  • 7
  • 19

4 Answers4

1

What's wrong with listView.getCheckedItemCount()?

Tishka17
  • 305
  • 2
  • 12
1
          lvMain.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, final View view, int position, long   id) 
        {
        int len = lvMain.getCount();
        SparseBooleanArray checked = lvMain.getCheckedItemPositions();
        for (int i = 1; i < len; i++){
        if (checked.get(i)) {
            count++;


               /* do whatever you want with the checked item */
           }

        }
        if(count>2)
        {
            /* do whatever you want with the checked item count more than one x value*/
            lvMain.setSelected(false);
            count=1;
        }
    }       

});
Ann
  • 727
  • 1
  • 7
  • 19
0

I think you are trying to count the total number of selected rows in multiple listView.

for(i=0; listCount; i++) {
    if(mListView.isItemChecked(i)){

    }
    else {

    }
}
juhan_h
  • 3,965
  • 4
  • 29
  • 35
0

Else, you could try to store your checkboxes and the other element displayed in a row (I've used TextView in my example) in a HashMap when overridden getView method get called and then count how many elements are checked iterating over the Map :

Iterator<Entry<TextView, CheckBox>> it = listCheck.entrySet().iterator();
    int i = 0;
    while (it.hasNext()) {
        Entry<TextView, CheckBox> entry = it.next();
        if (entry.getValue().isChecked()) 
                i++;
    }   
    return i;
Sw4Tish
  • 202
  • 4
  • 12