I have a dynamic listview with one text and one checkbox per line.when i click a button.,i need to get all checked item names & Unchecked item names separately as arraylilst.How could i do that.Examples are much better..
I used..
    SparseBooleanArray checked = mainlw.getCheckedItemPositions();
    for (int i = 0; i < checked.size(); i++) {
        if(checked.valueAt(i) == true) {
            Planet tag = (Planet) mainlw.getItemAtPosition(checked.keyAt(i));
            String selectedName=tag.getName();
            Toast.makeText(getApplicationContext(), selectedName, Toast.LENGTH_SHORT).show();
        }
    }
                Try this out and implement this logic according to your requirement.
int cntChoice = myList.getCount();
String checked = "";
String unchecked = "";
SparseBooleanArray sparseBooleanArray = myList.getCheckedItemPositions();
for(int i = 0; i < cntChoice; i++)
{
     if(sparseBooleanArray.get(i) == true) 
     {
         checked += myList.getItemAtPosition(i).toString() + "\n";
     }
     else  if(sparseBooleanArray.get(i) == false) 
     {
         unchecked+= myList.getItemAtPosition(i).toString() + "\n";
     }
 }
                        use CHOICE_MODE_MULTIPLE in your ListView and use getCheckedItemPositions() to get the checked ones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With