I am developing an app which has a list view with custom layout as follows :
It has 4 RadioButtons in RadioGroup and a TextView. Actually, it ll be shown as question(TextView) and answers(RadioButtons) list. Above view is inflated in my custom adapter which extends ArrayAdapter<Question>.
The problem is that, how should I maintain the state of RadioButtons in my custom Adapter? When RadioButton is pressed/checked and list is scrolled down, adapter automatically recycles view and the RadioButton state is lost.
- So, can anyone guide to any link / information regarding this?
- Or how should I implement question answers list?
Article I followed:
http://www.vogella.de/articles/AndroidListView/article.html .
The above link is using a CheckBox, in similar manner I want to use the RadioGroup(RadioButtons) instead of CheckBoxes.
It’s easy to adapt that tutorial so you can use a
RadioGroupinstead of aCheckBox. Bellow is an example(I used aRadioGroupwith 4RadioButton). First of all you’ll have to modify theModelclass so it can hold the new data:Then modify the
getView()method to set the views according to the model:and then
ViewHolderclass:The xml layout with a
RadioGroup: