Android : ListView Mode is Multiple But does not select items

on Friday, August 29, 2014


I have set my ListView choice mode as below:



listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);


but after selecting some items and trying to Toast selected items it show me empty string .


how I Toast Selected Items:



String selected = "";
int cntChoice = listView.getCount();

SparseBooleanArray sparseBooleanArray = listView.getCheckedItemPositions();
for (int i = 0; i < cntChoice; i++) {
if (sparseBooleanArray.get(i)) {
selected +=listView.getItemAtPosition(i).toString() + "\n";
}
}
Toast.makeText(getApplicationContext(),selected,Toast.LENGTH_SHORT).show();


what is the problem ? and how can i solve it?


0 comments:

Post a Comment