RadioButton 多行 多列显示

来源:互联网 发布:windows和linux的区别 编辑:程序博客网 时间:2024/06/03 23:38

布局:

<RadioGroup            android:id="@+id/rg_first"            style="@style/rg_style"            android:orientation="horizontal">            <RadioButton                android:id="@+id/pay_issue"                style="@style/rg_rb_style"                android:text="@string/pay_issue" />            <RadioButton                android:id="@+id/cannot_play"                style="@style/rg_rb_style"                android:text="@string/cannot_play" />        </RadioGroup>        <RadioGroup            android:id="@+id/rg_second"            style="@style/rg_style"            android:orientation="horizontal">            <RadioButton                android:id="@+id/force_closure"                style="@style/rg_rb_style"                android:text="@string/force_closure" />            <RadioButton                android:id="@+id/play_pause"                style="@style/rg_rb_style"                android:text="@string/play_pause" />        </RadioGroup>        <RadioGroup            android:id="@+id/rg_third"            style="@style/rg_style"            android:orientation="horizontal">            <RadioButton                android:id="@+id/other_issues"                style="@style/rg_rb_style"                android:text="@string/other_issues" />        </RadioGroup>

Java:

public class FeedBackActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener{    private RadioGroup firstRG;    private RadioGroup secondRG;    private RadioGroup thirdRG;    public static Intent getFeedBackActivityIntent(Context context){        Intent feedBackIntent = new Intent(context, FeedBackActivity.class);       return feedBackIntent;    }    @Override    protected int getLayoutId() {        return R.layout.aty_feed_back;    }    @Override    protected void afterCreate() {        firstRG = (RadioGroup) findViewById(R.id.rg_first);        secondRG = (RadioGroup) findViewById(R.id.rg_second);        thirdRG = (RadioGroup) findViewById(R.id.rg_third);        firstRG.setOnCheckedChangeListener(this);        secondRG.setOnCheckedChangeListener(this);        thirdRG.setOnCheckedChangeListener(this);    }    @Override    public void onCheckedChanged(RadioGroup group, int checkedId) {        if(group != null && checkedId>0){            if(group == firstRG){                secondRG.clearCheck();                thirdRG.clearCheck();            }else if(group == secondRG){                firstRG.clearCheck();                thirdRG.clearCheck();            }else if(group == thirdRG){                firstRG.clearCheck();                secondRG.clearCheck();            }            group.check(checkedId);        }    }}


color.xml:

<style name="rg_style">        <item name="android:layout_width">match_parent</item>        <item name="android:layout_height">wrap_content</item>    </style>    <style name="rg_rb_style">        <item name="android:layout_width">wrap_content</item>        <item name="android:layout_height">wrap_content</item>        <item name="android:layout_weight">1</item>    </style>

效果图:



0 0
原创粉丝点击