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

  • SEARCH
  • Home
  • 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 7569081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:04:59+00:00 2026-05-30T15:04:59+00:00

Making a simple program which will generate a multiple choice form. I have an

  • 0

Making a simple program which will generate a multiple choice form. I have an sing_select.xml which acts as the template for making each question. Then, in code I wanted to populate my main.xml with a bunch of these templates customized. Though it works great for the first question, any subsequent questions do not get displayed. Not sure what I’m doing wrong. I know there isn’t an overlap as I manually hid the first question.

Java File

public class FormFillerActivity extends Activity
{
    private LinearLayout    mQuestionList;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        //Must come before setContentView or program crashes
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        //Must set before accessing layout elements or program crashes
        setContentView(R.layout.main);

        mQuestionList = (LinearLayout) findViewById(R.id.Body_Layout);

        initForm();
    }

    private void initForm()
    {
        int count = 1;

        ArrayList<String> answers = new ArrayList<String>();
        answers.add("Single");
        answers.add("Married");
        answers.add("Separated");
        answers.add("Divorced");
        mQuestionList.addView(addSingSelectQuestion(count++, "What is your marital status?", answers));

        answers.clear();
        answers.add("Male");
        answers.add("Female");
        mQuestionList.addView(addSingSelectQuestion(count++, "What is your gender?", answers));

    }

    private View addSingSelectQuestion(int count, String question, ArrayList<String> answers)
    {
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View container = inflater.inflate(R.layout.sing_select, null);

        ((TextView) container.findViewById(R.id.Sing_Select_Num)).setText(count + ") ");
        ((TextView) container.findViewById(R.id.Sing_Select_Text)).setText(question);

        RadioGroup rg = (RadioGroup) container.findViewById(R.id.Sing_Select_Answer);

        //Generate radio group answers
        Iterator<String> it = answers.iterator();
        while (it.hasNext())
        {
            RadioButton rb = new RadioButton(rg.getContext());
            RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT,
                    RadioGroup.LayoutParams.WRAP_CONTENT);
            String ans = it.next();

            rb.setId(answers.indexOf(ans));
            rb.setLayoutParams(params);
            rb.setText(ans);
            rb.setTextColor(getResources().getColor(R.color.black));
            rb.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.txt_normal));
            rg.addView(rb);
        }

        return container;
    }
}

main.xml (stripped out unrelated UI elements)

<?xml version="1.0" encoding="utf-8"?>
...
    <ScrollView
        android:id="@+id/Body_Scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/Footer"
        android:layout_below="@id/Title"
        android:scrollbars="vertical" >

        <LinearLayout
            android:id="@+id/Body_Layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/marg_normal"
            android:padding="@dimen/pad_large" >
        </LinearLayout>
    </ScrollView>
...

sing_select.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Sing_Select_Layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:padding="8dp" >

    <TextView
        android:id="@+id/Sing_Select_Num"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="#) "
        android:textColor="@color/black"
        android:textSize="@dimen/txt_normal" />

    <TextView
        android:id="@+id/Sing_Select_Text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/Sing_Select_Num"
        android:layout_toRightOf="@+id/Sing_Select_Num"
        android:text="The Question?"
        android:textColor="@color/black"
        android:textSize="@dimen/txt_normal" />

    <RadioGroup
        android:id="@+id/Sing_Select_Answer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/Sing_Select_Text"
        android:layout_below="@+id/Sing_Select_Text"
        android:layout_toLeftOf="@+id/Sing_Select_Trans_Button" >
    </RadioGroup>

    <Button
        android:id="@+id/Sing_Select_Trans_Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:background="@drawable/btn_big"
        android:padding="8dp"
        android:text="Accept"
        android:textSize="@dimen/txt_button" />

</RelativeLayout>
  • 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-30T15:05:00+00:00Added an answer on May 30, 2026 at 3:05 pm

    Try to set orientation to vertical for the *Body_Layout* LinearLayout. I think your pushing out of the screen the next rows after the first one(the width for the inflated view is set to fill the parent).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a relatively simple program which will also be running on a few
I'm making a simple form that is to step through a program iteratively. How
I am making a simple program which suppose to accept txt file data from
I have a program in which I need to apply a 2-dimensional texture (simple
Hello I am making a simple program which is taking input from user and
I am making a simple program which abstracts complex numbers and complex number operations.
Simple synopsis: I have a program which needs authentication from user to get access
so I'm making a really simple program in which I want one sprite to
I'm making a simple program in Objective-C. It has one class with a lot
I am working on making a simple drawing program. So far I am able

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.