jeudi 12 février 2015

Android custom listview with checkbox detect if no checkbox is checked

I have a menu item wherein if it is clicked I need to check first if a checkbox is checked. If not then display a toast message.


This is what I've tried so far:



SparseBooleanArray checkedPositions = lv.getCheckedItemPositions();
int size = checkedPositions.size();
for (int i = 0 ; i < size ; i++) {
// We get the key stored at the index 'i'
int key = checkedPositions.keyAt(i);
// We get the boolean value with the key
Log.i ("SavedItems", "checkedPositions(" + key + ") = " + checkedPositions.get(key));
}

if(size < 1) {
Toast.makeText(getActivity(), "No item selected", Toast.LENGTH_SHORT).show();
}


This is working if no checkbox is checked but if I check and uncheck it's not firing the toast message. Any ideas? Thanks.





Aucun commentaire:

Enregistrer un commentaire