开发者

List of RadioButtons on Android, Java

开发者 https://www.devze.com 2023-04-03 22:41 出处:网络
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

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" />
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号