我正在创建RadioButton并将它们动态添加到RadioGroup。 但是当我运行应用程序时,RadioButtons的文本没有显示在屏幕上。RadioButton.setText()不显示文本
这是我的单选按钮
else if ((items.get(i).toString()).equals("rad")) {
RadioGroup bg = new RadioGroup(getApplicationContext());
int child=0;
for (int h = textlen; h < text.size(); textlen++) {
if (text.get(textlen).contains("(")) {
s = text.get(textlen).replace("(", "");
if (s.contains(")"))
s = s.replace(")", "");
} else if (text.get(textlen).contains(")")) {
s = text.get(textlen).replace(")", "");
} else
s = text.get(textlen);
RadioButton radioButton = new RadioButton(
getApplicationContext());
bg.addView(radioButton);
///radioButton.setName("rbt");
if (s.contains("{on}")) {
// radioButton.setSelected(true);
radioButton.setChecked(true);
s = s.replace("{on}", "");
} else {
radioButton.setChecked(false);
s = s.replace("{of}", "");
}
//((RadioButton)bg.getChildAt(child)).setText(s);
//child++;
radioButton.setText(s);
String c = text.get(textlen).substring(
text.get(textlen).length() - 1);
if (c.equals(")")) {
textlen++;
break;
}
}
layout.addView(bg);
}
当我调试的代码,我可以看到文本添加到RadioGropus孩子
但上运行的应用程序中的文本是不可见的代码。 任何人都可以检测到问题。 非常感谢
尝试设置文本,然后使用'bg.addView(radioButton);'也可以通过setId() ' – 2014-10-28 07:31:29