List of RadioButtons on Android, Java
I need create a list of RadioButtons, but if I try to do it with ListView than I can select all radiobuttons simultaneously, but I need 1 selected radiobutton simultaneously. Therefore, I can try this code:
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);
But layout doesn't show all items, because layout is small. I need scrollbar or ano开发者_运维技巧ther mean for my task. Help me please.
You should set your ListView
to single mode. For this add android:choiceMode="singleChoice"
to layout that contains your ListView
:
<ListView ... android:choiceMode="singleChoice" />
精彩评论