我arrayList [5,8,13,18,19]从服务器获取,我想RadioGroup在xml文件中创建一个.选择可解决的项目后,我会将所选项目放入arrayList并在单击确定按钮后将查询发送到服务器.我怎样才能以编程方式创建RadioGroup?
我试过这个,但我不知道如何设置值RadioButton与ArrayList值.我怎样才能让tp工作?
private void createRadioButton(final ArrayList<Integer> items) {
final LinearLayout ll = (LinearLayout) findViewById(R.id.lila);
final ArrayList<RadioButton> rb = new ArrayList<RadioButton>();
final RadioGroup rg = new RadioGroup(this); // create the RadioGroup
rg.setOrientation(RadioGroup.HORIZONTAL);// or RadioGroup.VERTICAL
for (int i = 0; i < items.size(); i++) {
items.get(i) = new RadioButton(this);
}
}
Run Code Online (Sandbox Code Playgroud)
试试这个
final RadioGroup rg = new RadioGroup(this); // create the RadioGroup
rg.setOrientation(RadioGroup.HORIZONTAL);// or RadioGroup.VERTICAL
for (int i = 0; i < items.size(); i++) {
RadioButton rb = new RadioButton(this);
rb.setText(items.get(i)+"");
rg.addView(rb);
}
Run Code Online (Sandbox Code Playgroud)
随着addView您添加动态创建RadioButton的RadioGroup.
| 归档时间: |
|
| 查看次数: |
1309 次 |
| 最近记录: |