在Android单选按钮列表,爪哇 [英] List of RadioButtons on Android, Java

查看:244
本文介绍了在Android单选按钮列表,爪哇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建单选按钮列表,但如果我试图用的ListView做的比我可以同时选择所有的单选按钮,但我需要1选择单选按钮同步。因此,我可以试试这个code:

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 another mean for my task. Help me please.

推荐答案

您应该设置你的的ListView 到单模式。对于这种添加安卓choiceMode =singleChoice来布局包含您的的ListView

You should set your ListView to single mode. For this add android:choiceMode="singleChoice" to layout that contains your ListView:

 <ListView ... android:choiceMode="singleChoice" />

这篇关于在Android单选按钮列表,爪哇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆