开发者

Android radio group

开发者 https://www.devze.com 2023-03-15 01:46 出处:网络
Im creating RadioGroup, inside that radio button. How can i get the selected values in radio button to store in array list?

Im creating RadioGroup, inside that radio button. How can i get the selected values in radio button to store in array list?

TableLayout ch = (TableLayout) findViewById(R.id.tablechild);
TableRow row2 = new TableRow(Edittextsample.this);
TextView m = new TextView(Edittextsample.this);
m.setText("Meals");
RadioGroup rg2 = new RadioGroup(Edittextsample.this);
rg2.setOrientation(TableLayout.HORIZONTAL);
RadioButton r = new RadioButton(Edittexts开发者_运维百科ample.this)
r.setText("Veg");
r.setTextSize(12);
rg2.addView(r);

RadioButton r1 = new RadioButton(Edittextsample.this)
r1.setText("Non-Veg");
 r1.setTextSize(12);
rg2.addView(r); 
ch.addView(row2,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,    LayoutParams.WRAP_CONTENT));


int selectedRadioId = rg2.getCheckedRadioButtonId();
RadioButton selectedRadioButton = rg2.findViewById(selectedRadioId);
String selectedText = selectedRadioButton.getText(); // "Veg" or "Non-veg"
0

精彩评论

暂无评论...
验证码 换一张
取 消