I am trying to multi-select list-view by setting drawable in OnItemClickListener,but when I scroll the list-view selected items loses drawable which I have changed on listview.OnitemClickListener in ItemChecked method.
What all I have tried :
1.Using xml selector in drawable
2.Tried changing drawable of selecteditems in custom adapter.
None of the above is working neither any of solution on stackoverflow.
Here is my adapter:
public class QuestionsOptionsAdapterMultipleSelectionLV extends BaseAdapter {
Context context;
ArrayList<QuestionOptionsModel> items;
String which;
CollegepondSandbox cs;
ArrayList<String> arr;
boolean isTouch = false;
int positionselected;
QuestionsOptionsAdapterMultipleSelectionLV adapter1;
public QuestionsOptionsAdapterMultipleSelectionLV(Context context,
ArrayList<QuestionOptionsModel> items) {
this.context = context;
this.items = items;
this.which = which;
this.arr = arr;
cs = new CollegepondSandbox();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return items.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return items.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
// positionselected =items.indexOf(items.get(position));
return items.indexOf(items.get(position));
}
@Override
public int getViewTypeCount() {
return getCount();
}
@Override
public int getItemViewType(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup
parent) {
if(convertView==null){
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.custom_options_multiple,
null);
WebView tvOptiontext;
ImageView ivOption;
LinearLayout llOptionsMultiple;
ivOption = (ImageView) convertView.findViewById(R.id.cbOption);
tvOptiontext = (WebView) convertView.findViewById(R.id.tvOptiontext);
llOptionsMultiple = (LinearLayout) convertView.findViewById(R.id.llOptionsMultiple);
tvOptiontext.loadData(items.get(position).QOption, "text/html", "utf-8");
return convertView;
}
}
here is my OnItemClickListener:
lvOption.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lvOption.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(final AdapterView<?> parent, View view, int position, long id) {
ivOption = (ImageView) view.findViewById(R.id.cbOption);
if (lvOption.isItemChecked(position)) {
ivOption.setImageResource(R.drawable.tick_2);
multipleSelectedIDs.add(answersal.get(position).QIsCorrect);
} else {
ivOption.setImageResource(R.drawable.tick_1);
multipleSelectedIDs.remove(answersal.get(position).QIsCorrect);
}
});