OnCheckedChangeListener无法正常工作

时间:2017-06-12 16:40:11

标签: android listener radio-group oncheckedchanged

我正在尝试为Radio组设置一个事件监听器,但是当debbugging从未触发监听器时,为什么?这就是我如何设置无线电组以便按照附图中所示的方式进行查看,也许可能存在问题,enter image description here

XML中的

<RadioGroup
                        android:id="@+id/idchoice"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_margin="10dp"
                        android:background="@drawable/selectorevidence2"
                        android:orientation="horizontal"
                        android:padding="10dp">

                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:orientation="vertical">

                            <RadioButton
                                android:id="@+id/rb_cedula"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginRight="10dp"
                                android:text="@string/CC"
                                android:textColor="#8fb5e3" />

                            <RadioButton
                                android:id="@+id/rb_extranjeria"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginRight="10dp"
                                android:text="@string/CE"
                                android:textColor="#8fb5e3" />

                            <RadioButton
                                android:id="@+id/rb_nn"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginRight="10dp"
                                android:text="@string/NN"
                                android:textColor="#8fb5e3" />

                        </LinearLayout>

                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:orientation="vertical">

                            <RadioButton
                                android:id="@+id/rb_nui"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginRight="10dp"
                                android:text="@string/NUI"
                                android:textColor="#8fb5e3" />

                            <RadioButton
                                android:id="@+id/rb_passport"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginRight="10dp"
                                android:text="@string/PA"
                                android:textColor="#8fb5e3" />

                            <RadioButton
                                android:id="@+id/rb_nodoc"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginRight="10dp"
                                android:text="@string/NODOC"
                                android:textColor="#8fb5e3" />

                        </LinearLayout>

                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:orientation="vertical">

                            <RadioButton
                                android:id="@+id/rb_ti"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginRight="10dp"
                                android:text="@string/TI"
                                android:textColor="#8fb5e3" />
                        </LinearLayout>
                    </RadioGroup>

现在在我的片段中:

rg_IdChoice = (RadioGroup) view.findViewById(R.id.idchoice); rg_IdChoice.setOnCheckedChangeListener(onIdTypeListener);

和听众:

RadioGroup.OnCheckedChangeListener onIdTypeListener = new 
RadioGroup.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
        rg_IdChoice.clearCheck();
        switch (i){
            case R.id.rb_cedula:

VicitmEviSelected.setDocType(IpatValues.DocType.getDocTypes(0));
                break;
            case R.id.rb_extranjeria:

VicitmEviSelected.setDocType(IpatValues.DocType.getDocTypes(1));
                break;
            case R.id.rb_nn:

VicitmEviSelected.setDocType(IpatValues.DocType.getDocTypes(2));
                break;
            case R.id.rb_nui:

VicitmEviSelected.setDocType(IpatValues.DocType.getDocTypes(3));
                break;
            case R.id.rb_passport:

VicitmEviSelected.setDocType(IpatValues.DocType.getDocTypes(4));
                break;
            case R.id.rb_nodoc:

VicitmEviSelected.setDocType(IpatValues.DocType.getDocTypes(5));
                break;
            case R.id.rb_ti:

VicitmEviSelected.setDocType(IpatValues.DocType.getDocTypes(6));
                break;
        }
    }
};

任何人都可以看到我做错了什么,任何提示都会受到高度赞赏。

0 个答案:

没有答案