Android: How to get text of dynamically created radio button selected by the user? -


How do I get the text of the dynamically created radio button selected by the user? Here is my code:

  radio group triangular group = (radio group) searchVBIID (RD. RDGP1); // layout parameters to use when you add each radio button LinearLayout.LayoutParams Leautprm = new RadioGroup.LayoutParams (RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT); (Int i = 0; i & lt; 4; i for ++) (Final Radio button Nuradiobtn = new Radio button (this); C3 = to db.getAns (3); (int j = 0; j & lt; i; j ++) c3.moveToNext (); label = C 3kgetstring (0); newRadioButton.setText (label); newRadioButton.setId (6); Radiogroup.addView (Nyaredio button, Leautprrm);  

is waiting for the answer, Maqsood

an easy way If you are going to do something special, depending on that button, you should check the ID instead of the label .

  radiogroup.setOnCheckedChangeListener (new RadioGroup.OnCheckedChangeListener () {Check onChheededChanged (RadioGroup rg, Int Czech id) {for (ii) I & lt; rg.getChildCount (); i ++ } {Rediobutn Bitian = (radio button) RG .getChildAt (i); if (btn.getId () == checkedId) to do with {string text = Btn.getText (); // text return;}}}} );  

Comments