Stop Refreshing on List View With Check Box / Radio Button
Hi!
In our Development, Mostly Developers facing one common problem while developing listview with CheckBox / Radio Buttons.
After you load your data on Listview, when you scroll the listview the selected items will disappear and some items will selected automatically. this problem is because of we are try to figure out the item by position. But when the listview is scrolled up / down the position will be reset.
The solution is we have to take the components tag position by getTag(), and we can identify by this tag position. But should set the Tag before set the value on the Item.
On Business Class
boolean P_is_checked;
i have create a boolean value to carry the state.
On The Adapter Class
{
// radio button on checkedchangelistener
rb_p.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// Step - 1 get the tag position while it is checked
int getPosition = (Integer) buttonView.getTag();
// Step - 2 On The Business Class Object set the boolean value state
A_list.get(getPosition).setP_is_checked(buttonView.isChecked());
}
});
// Step - 3 set the Tag position
rb_p.setTag(position);
//Step - 4 Set the value of the item
rb_p.setChecked(A_list.get(position).P_is_checked);
}
Thats all, no your listview the CheckBox / RadioButton will never check or unchecked automatically while scrolling..,
Enjoy..,
Thank You!
Please Leave Your Comment..,
Have A Happy Day..,