【Android】Android单选按钮控件的使用

30 篇文章 0 订阅


<RadioGroup
        android:id="@+id/function_group"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_toStartOf="@+id/imageView2"
        android:layout_toLeftOf="@+id/imageView2">

        <RadioButton
            android:text="肤色手势分割"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/radioButton" />

        <RadioButton
    android:text="红色对象识别"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/radioButton2"/>

        <RadioButton
        android:text="特征匹配定位"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/radioButton3" />

    </RadioGroup>

 private RadioGroup function=null;
    private RadioButton radio1=null;
    private RadioButton radio2=null;
    private RadioButton radio3=null;
    private Boolean bIsRun1 = false;
    private Boolean bIsRun2 = false;
    private Boolean bIsRun3 = false;

function =(RadioGroup) super.findViewById(R.id.function_group);
        radio1   =(RadioButton) super.findViewById(R.id.radioButton);
        radio2   =(RadioButton) super.findViewById(R.id.radioButton2);
        radio3   =(RadioButton) super.findViewById(R.id.radioButton3);

        function.setOnCheckedChangeListener(new OnCheckedChangeListenerImp());

private class OnCheckedChangeListenerImp implements RadioGroup.OnCheckedChangeListener {

        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (MainActivity.this.radio1.getId() == checkedId){
                bIsRun1 = true;
                bIsRun2 = false;
                bIsRun3 = false;
            } else if(MainActivity.this.radio2.getId() == checkedId){
                bIsRun1 = false;
                bIsRun2 = true;
                bIsRun3 = false;
            }
            else if(MainActivity.this.radio3.getId() == checkedId){
                bIsRun1 = false;
                bIsRun2 = false;
                bIsRun3 = true;
            }
        }
    }








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值