Radiobutton Selection Jumps Is Auto Selected On Other Custom Listview
Solution 1:
What do you do in OnCheckChanged? I had a similar issue and in my case, it was because I was using the position from
public View getView(int position, View convertView, ViewGroup parent)
to update the data onCheckChanged.
What eventually solved it for me, is 1. Using the ViewHolder pattern. 2. When updating the data onCheckChanged, the position I used for data.get(NewPosition).set...(true) was not the position from the getview, rather from :
int getPosition = (Integer) group.getTag();
The getTag(); comes from using the Viewholder pattern and group comes from:
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
publicvoidonCheckedChanged(RadioGroup group, int checkedId) {
int getPosition = (Integer) group.getTag();//do thisswitch (checkedId) {
case R.id.presentRDO:
//some code here....
studentsList.get(getPosition).setPresent(true);//do thisbreak;
}
Hope this helps you.
Do this:
if (convertView == null) {
inflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.layout_list_content, null);
holder = new ViewHolder();
// initialization here
holder.name = (TextView) convertView.findViewById(R.id.nameListTV);
holder.date = (TextView) convertView.findViewById(R.id.dateTV);
holder.radioGroup = (RadioGroup) convertView
.findViewById(R.id.attendanceRDG);
holder.presentRDOButton = (RadioButton) convertView
.findViewById(R.id.presentRDO);
holder.absentRDOButton = (RadioButton) convertView
.findViewById(R.id.absentRDO);
holder.leaveRDOButton = (RadioButton) convertView
.findViewById(R.id.leaveRDO);
convertView.setTag(R.id.attendanceRDG, holder.radioGroup);//do for all views
}
} else {
viewHolder = (ViewHolderItem) convertView.getTag();
}
holder.radioGroup.setTag(position);//Similarly for all elements
holder.radioGroup
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
publicvoidonCheckedChanged(RadioGroup group,
int checkedId) {
int getPosition = (Integer) group.getTag();
studentsList.get(getPosition). //problem hereswitch (checkedId) {
case R.id.presentRDO:
//code goes herebreak;
}
});
Solution 2:
Okay! at last i got my answer!
Basically all i needed was to add 3 static final
variables and use them for saving the state of the radioButton clicked.
Please follow this answer, this is the most simple answer all over the internet.
Thanks @hrishitiwari for pointing to the answer.
Post a Comment for "Radiobutton Selection Jumps Is Auto Selected On Other Custom Listview"