I use customize listview with checkbox.while scrolling the listview the checked state is interchanged how to control interchanged and set it default ie checked items i sele
At last I found answer to above question. In this code check value and TextView
value is not changing while we scroll the ListView
BaseAdapter
use ArrayAdapter
for customlistviewgetview()
as I prescribed belowCode
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.subtag, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.subtag_textCatagory);
viewHolder.check = (CheckBox) view.findViewById(R.id.subtag_checkCatagory);
viewHolder.text.setOnClickListener(this);
viewHolder.check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
TagBojo element = (TagBojo) viewHolder.check.getTag();
element.setSelected(buttonView.isChecked());
System.out.println(element.getListName());
});
view.setTag(viewHolder);
viewHolder.check.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).check.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getListName());
holder.check.setChecked(list.get(position).getSelected());
return view;
}