我需要创建一个RadioButtons列表,但如果我尝试使用ListView,我可以同时选择所有的radiobutton,但我需要同时选择1个radiobutton。因此,我可以试试这段代码:
RadioGroup group=new RadioGroup(this);
LinearLayout layout=(LinearLayout)findViewById(R.id.linearLayout2);
for (String item:mMusicData.keySet()) {
RadioButton button=new RadioButton(this);
button.setText(item);
group.addView(button);
}
layout.addView(group);
但布局不会显示所有项目,因为布局很小。我的任务需要滚动条或其他方法。请帮帮我。
答案 0 :(得分:0)
您应该将ListView
设置为单一模式。为此,将android:choiceMode="singleChoice"
添加到包含ListView
:
<ListView ... android:choiceMode="singleChoice" />