安卓广播组

标签 android radio-button

我正在创建 RadioGroup,在 radio button 中。 如何获取单选按钮中的选定值以存储在数组列表中?

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(Edittextsample.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"

关于安卓广播组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6437887/

相关文章:

Android Light AppTheme with Dark ActionBar (AppCompat)

jquery - 同一事件的两个单独的处理程序

javascript - 第二次单击时清除/取消选择单选按钮

html - 纯 CSS 幻灯片单选按钮(第四个按钮作为第一个?)

react-native - 自定义单选按钮在 native react 中不起作用

android - 在 Android 中使用 loadDataWithBaseURL() 显示图像时出现问题

android: 帮助创建表格布局

jquery - 单选按钮添加类元素

android - 如何使用文本+图像动态填充 Android 微调器

android - android 中的圆角菜单