【问题标题】:Managing RadioButton with RelativeLayouts使用相对布局管理单选按钮
【发布时间】:2012-02-08 11:34:30
【问题描述】:

我有一个活动,用户必须从列表中选择一个选项。

例如:

<relativeLayout>
   <relativeLayout> <radiobutton> <textview>
   <relativeLayout> <radiobutton> <textview> <edittext> <textview>
   <relativeLayout> <radiobutton> <textview> <spinner> <textview>
<relativeLayout>

因此,任何时候只能选择一个单选按钮。

执行此操作的最佳方法可能是使用 radioGroup 来管理这些按钮。由于设置了 relativeLayouts,radioGroup 不能用于确保在任何时候只选中一个单选按钮。

除了手动管理单选按钮的行为(即 onClick,将其他单选按钮设置为未选中)之外,还有更好的方法吗?

【问题讨论】:

    标签: android android-layout coding-style


    【解决方案1】:

    是的.. 如果您将条件放入您的 xml 布局中,它将完成。 喜欢:

    RadioButton android:checked="false"
    
    <RadioGroup android:layout_width="fill_parent"
    
                android:layout_height="wrap_content" android:orientation="vertical"
    
                id="@+id/group1">
    
                <TextView android:layout_width="fill_parent"
    
                        android:layout_height="wrap_content"
    
                        android:text="Q1: What is Android?" android:textStyle="bold" />
    
                <RadioButton android:checked="false"
    
                        android:text="@string/radio_group_1_option1" id="@+id/option1" />
    
                <RadioButton android:checked="false"
    
                        android:text="@string/radio_group_1_option2" id="@+id/option2" />
    
                <RadioButton android:checked="false"
    
                        android:text="@string/radio_group_1_option3" id="@+id/option3" />
    
        </RadioGroup>
    

    【讨论】:

    • 哦.!!@PareshMayani 是不是错了,然后指导 yaar?我随时准备向你学习..
    • 我认为这不是完美的解决方案,因为他已经提到要使用 RadioGroup。
    • 嗨,问题是如果我在布局设计中使用 radiogroup,相关布局将嵌套在 radiogroup 中。我已经尝试过了,radiogroup 行为停止工作(即可以选择多个单选按钮)
    猜你喜欢
    • 1970-01-01
    • 2011-04-26
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多