In each row of my ListView
I have a RadioGroup
with RadioButton
s.
From the database I get five rows and when I check the RadioButtons in the first row and then scroll I see that the third row is getting checked too (on screen, not database).
When I check RadioButtons in the second row, the fourth row is getting checked too.
Screen placed a 1,5 rows.
public void bindView(View view, Context _context, Cursor _cursor) {
String id=_cursor.getString(_cursor.getColumnIndex("_id"));
RadioButton RightRadio=(RadioButton)view.findViewById(R.id.RightRadio);
RightRadio.setOnClickListener(radioListener);
RightRadio.setTag(id);
RadioButton LeftRadio=(RadioButton)view.findViewById(R.id.LeftRadio);
LeftRadio.setOnClickListener(radioListener);
LeftRadio.setTag(id);
RadioButton UpRadio=(RadioButton)view.findViewById(R.id.UpRadio);
UpRadio.setOnClickListener(radioListener);
UpRadio.setTag(id);
RadioButton DownRadio=(RadioButton)view.findViewById(R.id.DownRadio);
DownRadio.setOnClickListener(radioListener);
DownRadio.setTag(id);
int oper=getOperByid(id);
switch (oper) {
case 1:
RightRadio.setChecked(true);
break;
case 3:
LeftRadio.setChecked(true);
break;
case 4:
UpRadio.setChecked(true);
break;
case 2:
DownRadio.setChecked(true);
break;
}
if (portrait) {
LeftRadio.setVisibility(View.GONE);
RightRadio.setVisibility(View.GONE);
UpRadio.setVisibility(View.VISIBLE);
DownRadio.setVisibility(View.VISIBLE);
} else {
UpRadio.setVisibility(View.GONE);
DownRadio.setVisibility(View.GONE);
LeftRadio.setVisibility(View.VISIBLE);
RightRadio.setVisibility(View.VISIBLE);
}
}
there is some problem with the checkboxes and radiobuttons in gridview and listview,do it like this in your adapter,declare an arraylist to hold the checked positions of your radiobuttons
private ArrayList<Boolean> itemChecked = new ArrayList<Boolean>();
in adapter constructor:-
public YourAdapter(Context context, ArrayList<String> mlist)
{
......your other intializations;
for (int i = 0; i < this.getCount(); i++)
{
itemChecked.add(i, false/true);
}
}
initialize as false or true depending on the value of the positions,and get the value in your bindview method as:-
radiobutton.setChecked(itemChecked.get(position));