Reputation: 687
I am using a listview with an effientadapter.
In my effiicient adapter I initialized and arraylist
public static ArrayList<String> stringPosition = new ArrayList<String>();
and populate it using where position in arraylist is 1 and 2.
stringPosition.add(position);
Then in my listview activity in onintemclicklister I check if values stored match the position. but when I click of more than one stored value in arraylist. I get only the last item in the arraylist. how can I
Comparing string with values from arraylist and check if match.
for (int i=0;i<EfficientAdapter.stringPosition.size();i++){
String x = EfficientAdapter.stringPosition.get(i).toString();
System.out.println("x: " +x);
if (x.equals(String.valueOf(position)))
DetailWork.GREEN_OR_BLUE=1;
else
DetailWork.GREEN_OR_BLUE=0;
}
how can I solved this issue and is it the best way to compare if some element of listrows is identical to list position. ?
Upvotes: 0
Views: 1451
Reputation: 6610
I can't edit my comment anymore...
for CHOICE_MODE_MULTIPLE
use
SparseBooleanArray sba = listView.getCheckedItemPositions();
for CHOICE_MODE_SINGLE
use int pos = listView.getSelectedItemPosition();
You can later fetch all these positions from your adapter.
Upvotes: 2