Recyclerview单选按钮组获取选中的单选

问题描述 投票:0回答:2

我在recylerview行中有以下内容

<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:id="@+id/radioItems"
            android:layout_height="wrap_content"
            android:weightSum="2"
            android:orientation="horizontal">
            <RadioButton android:id="@+id/radio_yes"
                android:layout_width="wrap_content"
                android:layout_weight="0.8"
                android:layout_height="wrap_content"
                android:textSize="12sp"
                android:text="Yes"/>
            <RadioButton android:id="@+id/radio_no"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:textSize="12sp"
                android:layout_height="wrap_content"
                android:text="No"/>
        </RadioGroup>

所以我想在我的recyclerview适配器中侦听检查无线电组项并获取是否已检查是或否。因此我在bindviewholder上的recyclerview中有[]

      holder.radioItems.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            Log.i("test",""+group.getCheckedRadioButtonId());
        }
    });

但是当我检查日志时,可以看到类似2131230980, 2131230979的值,但看不到单选按钮的ID

我希望在日志中看到radio_yesradio_no的ID。我在这方面错过了什么。我仍然想使用单选按钮,而不是独立的单选按钮。

我在recylerview行项目中具有以下内容

java android android-recyclerview android-radiogroup
2个回答
0
投票

0
投票

您可以简单地使用开关盒在setOnCheckedChangeListener

© www.soinside.com 2019 - 2024. All rights reserved.