java如何将HashMap的值映射到单选按钮
我是Android新手,尝试将文本设置为RadioButons。我使用Hashmap方法从列表字符串(Hashmap)中获取值。我可以在日志视图中显示该值,但无法在单选按钮上显示文本
请检查代码并提出解决方案
RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);
radioGroup = new RadioGroup(this);
final RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
key = entry.getKey();
values = entry.getValue() != null;
System.out.println("Key = " + key);
System.out.println("Values = " + values + "n");
RadioButton radioButtonView = new RadioButton(this);
radioButtonView.setFreezesText(values);
radioGroup.addView(radioButtonView, p);
}
提前谢谢
# 1 楼答案
使用这段代码可能会对你有所帮助