I have a situation to select one radio button from dynamically created radio buttons. I know it is possible with Radio group but still I am not able to do it because my situation is little different. Let me explain it.
I have a question like "A recent survey found that in British secondary schools" with 4 options like
A.
B.
C.
D.
All data coming from the server in json form. I have created the view dynamically with one question and four options with radio buttons. But what i am understanding is every row is new row and I am not able to select only one radio buttons from all radio buttons. Every button is selecting individually but I want to select only one radio button on which I click.
Any help would be appreciated.
you can see my view below:
My code is :
LinearLayout linearLayoutForQuestions = (LinearLayout) view.findViewById(R.id.questionsLinearLayout);
linearLayoutForQuestions.removeAllViews();
//set the questions for the user
for (int ss = 0; ss < totalNoOfQuestions.size(); ss++) {
final List<String> list = new ArrayList();
list.add("SELECT");
TextView textView = new TextView(activity);
textView.setTextSize(15);
textView.setTextColor(view.getResources().getColor(R.color.black));
textView.setTypeface(typeface1);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, 20, 0, 0);
textView.setLayoutParams(params);
String question = totalNoOfQuestions.get(ss).getQuestions();
String questionNo = totalNoOfQuestions.get(ss).QuestionNo;
textView.setText("Question " + questionNo + " " + question);
//linearlayout and set data inside it
LinearLayout parent = new LinearLayout(activity);
parent.removeAllViews();
parent.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
parent.setOrientation(LinearLayout.VERTICAL);
int optionSize = totalNoOfQuestions.get(ss).getOptions().size();
for (int s = 0; s < optionSize; s++) {
//children of parent linearlayout
LinearLayout layout2 = new LinearLayout(activity);
layout2.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
layout2.setOrientation(LinearLayout.HORIZONTAL);
layout2.setGravity(Gravity.CENTER);
String optionNo = totalNoOfQuestions.get(ss).getOptions().get(s).getQuestionOptionNo();
TextView textView1 = new TextView(activity);
textView1.setText(optionNo);
textView.setTextSize(15);
final RadioButton radioButton = new RadioButton(activity.getApplicationContext());
radioButton.setId(s);
radioButton.setBackgroundResource(R.drawable.settings_background_ripple);
LinearLayout.LayoutParams pa = new LinearLayout.LayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
pa.setMargins(10,10,10,10);
radioButton.setLayoutParams(pa);
radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int checkedRadioButtonId = buttonView.getId();
Toast.makeText(activity, "hit it", Toast.LENGTH_SHORT).show();
}
});
String questionOption = totalNoOfQuestions.get(ss).getOptions().get(s).getQuestionOption();
TextView textView2 = new TextView(activity);
textView2.setTextSize(15);
textView2.setText(questionOption);
layout2.addView(textView1);
layout2.addView(radioButton);
layout2.addView(textView2);
parent.addView(layout2);
}
linearLayoutForQuestions.addView(textView);
linearLayoutForQuestions.addView(parent);
}
I have been working on it from a while and finally I find the way how to do it , posting my answer to let others take idea from it. I make it work by taking the array of Textview and Radiogroup outside the inner for loop.
Thank you everyone for the assistance. Happy Coding:)
LinearLayout linearLayoutForQuestions = (LinearLayout) view.findViewById(R.id.questionsLinearLayout);
linearLayoutForQuestions.removeAllViews();
totalNoOfQuestions = readingTests[countReadingTest].getQuestion();
//set the questions for the user
for (int ss = 0; ss < totalNoOfQuestions.size(); ss++) {
groupNo = ss;
final List<String> list = new ArrayList();
list.add("SELECT");
TextView textView = new TextView(activity);
textView.setTextSize(15);
textView.setTextColor(view.getResources().getColor(R.color.black));
textView.setTypeface(typeface1);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, 20, 0, 0);
textView.setLayoutParams(params);
String question = totalNoOfQuestions.get(ss).getQuestions();
String questionNum = totalNoOfQuestions.get(ss).QuestionNo;
textView.setText("Question " + questionNum + " " + question);
//linearlayout and set data inside it
LinearLayout parent = new LinearLayout(activity);
parent.removeAllViews();
parent.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
parent.setOrientation(LinearLayout.VERTICAL);
final int optionSize = totalNoOfQuestions.get(ss).getOptions().size();
final RadioButton[] radioButton = new RadioButton[optionSize];
int size = totalNoOfQuestions.size();
final RadioGroup[] radioGroup = new RadioGroup[size]; //you can also create in xml
radioGroup[ss] = new RadioGroup(activity);
radioGroup[ss].setId(ss + 100);
radioGroup[ss].setOrientation(RadioGroup.VERTICAL)ΓΈ;
//this textview is for the optionsNo like A,B,C,D
final TextView[] textView1 = new TextView[optionSize];
LinearLayout layoutOptionsNo = new LinearLayout(activity);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
layoutOptionsNo.setOrientation(LinearLayout.VERTICAL);
layoutOptionsNo.setWeightSum(optionSize);
layoutOptionsNo.setGravity(Gravity.CENTER);
layoutOptionsNo.setPadding(10, 0, 0, 0);
layoutOptionsNo.setLayoutParams(layoutParams);
LinearLayout layoutOptions = new LinearLayout(activity);
layoutOptions.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f));
layoutOptions.setOrientation(LinearLayout.HORIZONTAL);
layoutOptions.setWeightSum(4);
layoutOptions.setGravity(Gravity.CENTER);
//inner loop for the options for every single question
for (int s = 0; s < optionSize; s++) {
String optionNo = totalNoOfQuestions.get(ss).getOptions().get(s).getQuestionOptionNo();
textView1[s] = new TextView(activity);
textView1[s].setText(optionNo);
textView1[s].setTextSize(15);
textView1[s].setGravity(Gravity.CENTER);
LinearLayout.LayoutParams pa = new LinearLayout.LayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
pa.setMargins(10, 10, 10, 10);
pa.weight = 1;
textView1[s].setLayoutParams(pa);
String questionOption = totalNoOfQuestions.get(ss).getOptions().get(s).getQuestionOption();
radioButton[s] = new RadioButton(activity);
radioButton[s].setId(s);
radioButton[s].setText(questionOption);
radioButton[s].setTextSize(15);
radioButton[s].setPadding(2, 2, 2, 2);
radioButton[s].setBackgroundResource(R.drawable.settings_background_ripple);
LinearLayout.LayoutParams pa2 = new LinearLayout.LayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f));
pa2.setMargins(10, 10, 10, 10);
pa2.weight = 1;
radioGroup[ss].setLayoutParams(pa2);
radioGroup[ss].addView(radioButton[s]);
layoutOptionsNo.addView(textView1[s]);
}
radioGroup[ss].setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
int originalId ;
int id = group.getId();{
originalId = id-100;
}
questionNo = totalNoOfQuestions.get(originalId).getQuestionNo();
optionNo = totalNoOfQuestions.get(0).getOptions().get(checkedId).getQuestionOptionNo();
}
});
layoutOptions.addView(layoutOptionsNo);
layoutOptions.addView(radioGroup[ss]);
parent.addView(layoutOptions);
linearLayoutForQuestions.addView(textView);
linearLayoutForQuestions.addView(parent);
}
boolean showOptionHint = totalNoOfQuestions.get(0).OptionList;
LinearLayout linearLayoutForOptions = (LinearLayout) view.findViewById(R.id.optionsLinearLayout);
linearLayoutForOptions.removeAllViews();
if (showOptionHint == true) {
//dynamic creation of options under the quesiton layout
List<ReadingTest.QuestionBean.OptionsBean> questionOptions = readingTests[countReadingTest].getQuestion().get(0).getOptions();
for (int ss = 0; ss < questionOptions.size(); ss++) {
String options = questionOptions.get(ss).getQuestionOption();
String optionsNo = questionOptions.get(ss).getQuestionOptionNo();
TextView textView = new TextView(activity);
textView.setTextSize(18);
textView.setTypeface(typeface);
textView.setTextColor(view.getResources().getColor(R.color.black));
textView.setText(optionsNo + ". " + options);
linearLayoutForOptions.addView(textView);
}
}
Use RadioGroup as below:
LinearLayout layout = (LinearLayout) findViewById(R.id.layout); //layout defined in xml main activity layout
RadioGroup radioGroup = new RadioGroup(this); //you can also create in xml
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
layout.addView(radioGroup, p);
/*radio button 1*/
RadioButton radioButtonView1 = new RadioButton(this);
radioButtonView1.setText("RadioButton1");
radioButtonView1.setOnClickListener(this);
radioGroup.addView(radioButtonView1, p);
/*radio button 2*/
RadioButton radioButtonView2 = new RadioButton(this);
radioButtonView2.setText("RadioButton2");
radioButtonView2.setOnClickListener(mThisButtonListener);
radioGroup.addView(radioButtonView2, p);
/*radio button 3*/
RadioButton radioButtonView3 = new RadioButton(this);
radioButtonView3.setText("RadioButton3");
radioButtonView3.setOnClickListener(mThisButtonListener);
radioGroup.addView(radioButtonView3 , p);
/*radio button 4*/
RadioButton radioButtonView4 = new RadioButton(this);
radioButtonView4 .setText("RadioButton4");
radioButtonView4.setOnClickListener(mThisButtonListener);
radioGroup.addView(radioButtonView4 , p);
Here you can select only one option out of multiple
As you required how to select value, then please use following code snippet:
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
radioButton = (RadioButton) findViewById(checkedId);
Toast.makeText(getBaseContext(), radioButton.getText(), Toast.LENGTH_SHORT).show(); //text related to option selected.
}
}
);
Thanks
Hello #Sandeep Singh Bandral
You have done a great Work, Why you are doing such a heavy work
Just Create a Radio Group Work and assign a Id ,and call setOnCheckedChangeListener
You can see here
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// find which radio button is selected
if(checkedId == R.id.answer1) {
Toast.makeText(getApplicationContext(), "Answer1",
Toast.LENGTH_SHORT).show();
} else if(checkedId == R.id.answer2) {
Toast.makeText(getApplicationContext(), "Answer2",
Toast.LENGTH_SHORT).show();
}else if(checkedId == R.id.answer3) {
Toast.makeText(getApplicationContext(), "Answer3",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Answer4",
Toast.LENGTH_SHORT).show();
}
}
});
In the place of Toast ,DO YOUR STUFF
Test Case:if you don't know how many radio buttons for each Question, you can see the below code over here
radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
for(int i=0; i<radioGroup.getChildCount(); i++) {
RadioButton btn = (RadioButton) radioGroup.getChildAt(i);
if(btn.getId() == checkedId) {
String text = btn.getText();
// do something with text
return;
}
}
}
});
I know this is rather old, but I just had the same problem. The solution is to change the state of RadioButton after adding it to RadioGroup by addView(). I guess this is also what BAKUS tried to say by his sample code.
copied from here
I have a custom radio group dialog and i am inflating it dynamically.
In my onCreate() I am doing this
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
alarmType1 = (TextView) findViewById(R.id.tvAlarmType);
View view = LayoutInflater.from(this).inflate(R.layout.custom_layout, null, false);
radioAlarmtype = (RadioGroup) view.findViewById(R.id.radiogroup);
initRadioDialog();
then initializing the dialog with the following code
String string_Alarmtype[]={"Melody","Vibration","Melody and Vibration"};
public void initRadioDialog()
{
Context context=AlarmActivity.this;
dialog_radio=new Dialog(context);
dialog_radio.requestWindowFeature(Window.FEATURE_NO_TITLE);
View view = LayoutInflater.from(context).inflate(R.layout.custom_layout, null, false);
radioAlarmtype = (RadioGroup) view.findViewById(R.id.radiogroup);
RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(
RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.WRAP_CONTENT);
// add 3 radio buttons to the group
RadioButton rb;
for (int i = 0; i < 3; i++){
rb = new RadioButton(context);
rb.setText(string_Alarmtype[i]);
rb.setId(i);
radioAlarmtype.addView(rb, layoutParams);
}
radioAlarmtype.check(2);
radioAlarmtype.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// checkedId is the RadioButton selected
RadioButton rb = (RadioButton) findViewById(checkedId);
//alarmType1.setText(rb.getText());
Toast.makeText(AlarmActivity.this, checkedId + "", Toast.LENGTH_SHORT).show();
}
});
dialog_radio.setContentView(view);
}
but above commented line //alarmType1.setText(rb.getText());is causing a nullpointerException
so i tried it on my textview onClickListener
like this
View.OnClickListener alarmTypeListener = new View.OnClickListener() {
public void onClick(View v) {
dialog_radio.show();
RadioButton rb = (RadioButton) findViewById(radioAlarmtype.getCheckedRadioButtonId());
alarmType1.setText(rb.getText());//NUllpointerException here
Toast.makeText(AlarmActivity.this,"HEllo"+rb.getText(),Toast.LENGTH_SHORT).show();
//here also nullpointerException if I comment above line
}
};
But the problem still persist so how can i change the textview as change in the selection of radio button in my dialog.
Hi i created dynamic radiogroup with radiobutton.Now i want to get values from dynamic radiogroup. Below is my code
final RadioGroup rg = new RadioGroup(this);
rg.setId(questionNo);
RadioButton[] rb = new RadioButton[answers.length()];
for (int i = 0; i < answers.length(); i++) {
JSONObject answerObject = answers.getJSONObject(i);
rb[i] = new RadioButton(this);
rb[i].setText(answerObject.getString("AnswerValue"));
rb[i].setId(answerObject.getInt("AnswerId"));
rg.addView(rb[i]);
}
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
int selectedId = rg.getCheckedRadioButtonId();
Log.i("ID", String.valueOf(selectedId));
}
});
Button click event
submit_button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(rg.getCheckedRadioButtonId()!=-1){
int id= rg.getCheckedRadioButtonId();
View radioButton = rg.findViewById(id);
int radioId = rg.indexOfChild(radioButton);
RadioButton btn = (RadioButton) rg.getChildAt(radioId);
String selection = (String) btn.getText();
Log.i("selection", selection);
}
}
});
I am getting only last index of the radio group.
I know it's too late, But this may help someone else
While creating your Dynamic Radiobutton Group, Create a parent layout(Linear layout or Relative Layout)
All radio groups will be the child of that Layout and all radio button will be a child of the specific radio group.
Creating No of Dynamic Radio Group
Create all Dynamic radio group in a parent layout
Add all radio button to a group
Add all radio group to the parent layout
public RadioButton[] rb;
public RadioGroup grp;
public LinearLayout layoutmain; //Parent layout
for(int i=0;i<qus.size();i++) //No of Questions
{
rb = new RadioButton[size];
grp = new RadioGroup(this);
grp.setId(a+qus.get(i).qusetionId);
for(int j=0;j<qus.get(i).choices.size();j++) //No of Radio button in radio group
{
rb[j] = new RadioButton(this);
rb[j].setText(qus.get(i).choices.get(j).getChoiceText());
grp.addView(rb[j]); // adding button to group
}
layoutmain.addView(grp); // adding group to layout
}
Retrieve All selected button task
From parent, layout get all child
Find all radio group using the child Instance
Create an object for that radio group
using that object get the selected radio button
Button bt = (Button) findViewById(R.id.button);
bt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
for(int i=0;i<layoutmain.getChildCount();i++) //From the parent layout (Linear Layout) get the child
{
View child = layoutmain.getChildAt(i);
if(child instanceof RadioGroup) //Check weather its RadioGroup using its INSTANCE
{
RadioGroup rg = (RadioGroup) child; //create a RadioButton for each group
int selectedId = rg.getCheckedRadioButtonId(); // get the selected button
RadioButton radiochecked = (RadioButton) findViewById(selectedId);
Log.e("Radio",radiochecked.getText().toString()); //from the button get the selected text
}
}
} });
My layout xml looks like
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollview1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearlayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
I am creating radiogroup and adding radiobuttons through code
LinearLayout ll = (LinearLayout)findViewById(R.id.linearlayout1);
RadioGroup rg = new RadioGroup(this);
rg.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
rg.setOrientation(0);
while(itr.hasNext()){
final String drinkname = itr.next();
System.out.println("drinkname: "+drinkname);
RadioButton rb = new RadioButton(this);
rb.setText(drinkname);
rg.addView(rb);
}
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
//group.clearCheck();
int id = group.getCheckedRadioButtonId();
RadioButton selectrb = (RadioButton) findViewById(id);
System.out.println(selectrb.getText().toString());
WebMenu.drinkname = selectrb.getText().toString();
}
});
ll.addView(rg);
It is supposed to show 6 values; But it is showing only 3 properly and remaining looks like hidden. Can someone help me out?
Thanks in advance!!
With the current RadioGroup class implementation, you cannot have two rows of RadioButtons.
So, either you set an HorizontalScrollView to your layout and allow the user to scroll to see all the RadioButtons or you use two RadioGroups, each of them containing 3 RadioButtons.
So, using your example (with little variations), this last solution can be implemented like this:
LinearLayout ll = (LinearLayout)findViewById(R.id.linearlayout1);
RadioGroup rg = new RadioGroup(this);
RadioGroup rg2 = new RadioGroup(this);
rg.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
rg.setOrientation(LinearLayout.HORIZONTAL);
rg2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
rg2.setOrientation(LinearLayout.HORIZONTAL);
String [] drinks = new String [] {"Mountain Dew", "7Up", "Root Beer", "Pepsi", "Cola", "Ice Tea"};
int i = 0;
while(i<drinks.length){
final String drinkname = drinks[i];
Log.i(TAG, "drinkname: "+drinkname);
RadioButton rb = new RadioButton(this);
rb.setText(drinkname);
if(i %2==0)
rg.addView(rb);
else
rg2.addView(rb);
i++;
}
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
//unselect all radios in the other RadioGroup
if(rg2.getCheckedRadioButtonId()!=-1){
rg2.setOnCheckedChangeListener(null);
rg2.clearCheck();
rg2.setOnCheckedChangeListener(this);
}
int id = group.getCheckedRadioButtonId();
RadioButton selectrb = (RadioButton) findViewById(id);
if(selectrb != null){
Log.i(TAG,selectrb.getText().toString());
WebMenu.drinkname = selectrb.getText().toString();
}
}
});
rg2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
//unselect all radios in the other RadioGroup
if(rg.getCheckedRadioButtonId()!=-1){
rg.setOnCheckedChangeListener(null);
rg.clearCheck();
rg.setOnCheckedChangeListener(this);
}
int id = group.getCheckedRadioButtonId();
RadioButton selectrb = (RadioButton) findViewById(id);
if(selectrb != null){
Log.i(TAG,selectrb.getText().toString());
WebMenu.drinkname = selectrb.getText().toString();
}
}
});
ll.addView(rg);
ll.addView(rg2);
You just have to be careful with the fact that your two RadioGroups keep track of only 3 RadioButtons each. They do not communicate with each other and do not affect each other. So if you select one RadioButton from the first row (first RadioGroup), you still have your selection on the second RadioGroup and vice-versa. You have to manage this situation yourself.
Edit: One way to manage this is unselecting all the radioButtons in RadioGroup1, when we select one RadioButton in RadioGroup2 and vice-versa. I have added code to do that.
I want to create a series of radio buttons which correspond to an array of strings within an Android app. The radio buttons should toggle content to be displayed from the array. How do I do this?
You must add the radio buttons to a RadioGroup and then the RadioGroup to the layout
I miss some information like what is submit, but your code should look like:
private void createRadioButton() {
final RadioButton[] rb = new RadioButton[5];
RadioGroup rg = new RadioGroup(this); //create the RadioGroup
rg.setOrientation(RadioGroup.HORIZONTAL);//or RadioGroup.VERTICAL
for(int i=0; i<5; i++){
rb[i] = new RadioButton(this);
rg.addView(rb[i]); //the RadioButtons are added to the radioGroup instead of the layout
rb[i].setText("Test");
}
ll.addView(rg);//you add the whole RadioGroup to the layout
ll.addView(submit);
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
for(int i = 0; i < 5; i++) {
rg.removeView(rb[i]);//now the RadioButtons are in the RadioGroup
}
ll.removeView(submit);
Questions();
}
});
}
Another code for dynamically creating the radiobutton
<TableRow>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/radiobuttons">
</RadioGroup>
</TableRow>
Code:
public void makeRadioButtons(Vector tmpVector, int i, LinearLayout.LayoutParams lp)
{
RadioButton rb = new RadioButton(this);
rb.setText((String) tmpVector.elementAt(i));
//rg is private member of class which refers to the radio group which I find
//by id.
rg.addView(rb, 0, lp);
}