0

I am creating an attendance list of student at run time from database and wants to create dynamically radio buttons in groups against each student and then take their attendance values on a submit button: my code looks like

        Ll = new LinearLayout(this);
        rg = new RadioGroup(this); //create the RadioGroup
        rg.setOrientation(RadioGroup.HORIZONTAL);//or RadioGroup.VERTICAL

      RadioButton  rb1  = new RadioButton(this);
        rb1.setText("P");
        rb1.setId(id);
        rg.addView(rb1); //the RadioButtons are added to the radioGroup instead of the layout
        ///////////////////////////////////////////////
        RadioButton  rb2  = new RadioButton(this);
        rb2.setText("A");
        rb2.setId(id+1);
        rg.addView(rb2); //the RadioButtons are added to the radioGroup instead of the layout
        /////////////////////////////////////

        RadioButton  rb3  = new RadioButton(this);
        rb3.setText("L");
        rb3.setId(id+2);
        rg.addView(rb3); //the RadioButtons are added to the radioGroup instead of the layout


        Ll.addView(rg);//you add the whole RadioGroup to the layout

        tr.addView((View)Ll); // A

how can i get values from dynamically created radion groups in my Android activity

AADProgramming
  • 6,077
  • 11
  • 38
  • 58

1 Answers1

0

Hope this code will help you to get selected radio button value

 int selectedId = rg.getCheckedRadioButtonId();
    RadioButton radiochecked = (RadioButton) findViewById(selectedId);
    Toast.makeText(context,
            radiochecked.getText(), Toast.LENGTH_SHORT).show();
Shadik Khan
  • 1,217
  • 1
  • 8
  • 18
  • Respected Sadiq yes of course it works fine for a single radio group / but i have created more than one radio group from java ...... it just take single value not all ......... – Farooq Zaman Mar 03 '15 at 05:21
  • I am creating radio group at java as : rg = new RadioGroup(this); //create the RadioGroup – Farooq Zaman Mar 03 '15 at 05:24
  • Please check my answer for retrieving all values from dynamically created radio group https://stackoverflow.com/questions/30627623/how-to-get-values-from-dynamic-radiogroup-android/47030229#47030229 – livemaker Oct 31 '17 at 07:49