Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7560917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:01:49+00:00 2026-05-30T13:01:49+00:00

I am developing an app which has a list view with custom layout as

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:01:50+00:00Added an answer on May 30, 2026 at 1:01 pm

    It’s easy to adapt that tutorial so you can use a RadioGroup instead of a CheckBox. Bellow is an example(I used a RadioGroup with 4 RadioButton). First of all you’ll have to modify the Model class so it can hold the new data:

    public class Model {
    
        String question; // hold the question
        int current = NONE; // hold the answer picked by the user, initial is NONE(see below)
        public static final int NONE = 1000; // No answer selected
        public static final int ANSWER_ONE_SELECTED = 0; // first answer selected
        public static final int ANSWER_TWO_SELECTED = 1; // second answer selected
        public static final int ANSWER_THREE_SELECTED = 2; // third answer selected
        public static final int ANSWER_FOUR_SELECTED = 3; // forth answer selected
    
        public Model(String question) {
            this.question = question;  
        }
    
    }
    

    Then modify the getView() method to set the views according to the model:

    @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View v = convertView;
                ViewHolder holder = null;
    
                if (v == null) {
                    v = inflater.inflate(R.layout.the_row, parent, false);
                    holder = new ViewHolder(v);
                    v.setTag(holder);
                    holder.group
                            .setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
    
                                public void onCheckedChanged(RadioGroup group,
                                        int checkedId) {
                                    Integer pos = (Integer) group.getTag(); // To identify the Model object i get from the RadioGroup with getTag()
                                                                            //  an integer representing the actual position 
                                    Model element = list.get(pos);          
                                    switch (checkedId) { //set the Model to hold the answer the user picked
                                    case R.id.answer0:
                                        element.current = Model.ANSWER_ONE_SELECTED;
                                        break;
                                    case R.id.answer1:
                                        element.current = Model.ANSWER_TWO_SELECTED;
                                        break;
                                    case R.id.answer2:
                                        element.current = Model.ANSWER_THREE_SELECTED;
                                        break;
                                    case R.id.answer3:
                                        element.current = Model.ANSWER_FOUR_SELECTED;
                                        break;
                                    default:
                                        element.current = Model.NONE; // Something was wrong set to the default
                                    }
    
                                }
                            });
                } else {
                    holder = (ViewHolder) v.getTag();
                }
                holder.group.setTag(new Integer(position)); // I passed the current position as a tag
    
                holder.t.setText(list.get(position).question); // Set the question body
    
                if (list.get(position).current != Model.NONE) {
                    RadioButton r = (RadioButton) holder.group.getChildAt(list
                            .get(position).current);
                    r.setChecked(true);
                } else {
                    holder.group.clearCheck(); // This is required because although the Model could have the current 
                                               // position to NONE you could be dealing with a previous row where
                                               // the user already picked an answer. 
    
                }
                return v;
            }
    

    and then ViewHolder class:

    class ViewHolder {
        TextView t = null;
        RadioGroup group;
    
        ViewHolder(View v) {
            t = (TextView) v.findViewById(R.id.textView1);
            group = (RadioGroup) v.findViewById(R.id.group_me);
        }
    
    }
    

    The xml layout with a RadioGroup:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    
        <RadioGroup
            android:id="@+id/group_me"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
    
            <RadioButton
                android:id="@+id/answer0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="false"
                android:text="Ans0" />
    
            <RadioButton
                android:id="@+id/answer1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="false"
                android:text="Ans1" />
    
            <RadioButton
                android:id="@+id/answer2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="false"
                android:text="Ans2" />
    
            <RadioButton
                android:id="@+id/answer3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="false"
                android:text="Ans3" />
        </RadioGroup>
    
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am developing an app which contains a table view that has images
I'm developing an app which has a large amount of related form data to
Hy, I'm developing a Grails app which has to communicate with an existing Java
OK let me explain the scenario. I am developing an app which has a
I'm currently in the process of developing an app which has some very demanding
I'm developing a iPad app which has a popover which appears to show you
for a client, I have been developing an app which has been tailored to
I'm developing a facebook app which has the following structure: Browser window (facebook.com/page/xxxx) --
I'm developing an iPhone app at the moment using Appcelerator Titanium which has 3
I am developing an android app which has Facebook integration in it. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.