在android中,我编写了一个代码,用于在RadioGroup中显示user.answers ask questions,它有多个RadioButton,但是当用户单击一个RadioButton时,RadioButton不填充图形。radioGroup.setOnCheckedChangeListener的代码如下:
holder.radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(final RadioGroup group, final int checkedId) {
rb = group.findViewById(checkedId);
try {
//set time in mili
Thread.sleep(500);
}catch (Exception e){
e.printStackTrace();
}
if (correctAns.equals(rb.getText())) {
if (itemList.get(position).getLevel().equals("el"))
sumResultEl++;
else if (itemList.get(position).getLevel().equals("pre"))
sumResultPre++;
else
sumResultInter++;
}RecyclerView显示了RecyclerView.my问题。问题的xml如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:gravity="center">
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true">
<TextView
android:id="@+id/question_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:textSize="20dp"
android:paddingLeft="10dp"/>
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
>
<RadioButton
android:id="@+id/radio_button_answer1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:checked="false"
android:padding="10dp"
android:background="@android:color/white"/>
<RadioButton
android:id="@+id/radio_button_answer2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:checked="false"
android:padding="10dp"
android:background="@android:color/white"/>
<RadioButton
android:id="@+id/radio_button_answer3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:checked="false"
android:padding="10dp"
android:background="@android:color/white"/>
<RadioButton
android:id="@+id/radio_button_answer4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:checked="false"
android:padding="10dp"
android:background="@android:color/white"/>
</RadioGroup>
</LinearLayout>
</ScrollView>
</LinearLayout>发布于 2019-07-29 20:25:06
这可能是因为背景的颜色和单选按钮的色调相同
尝试将RadioGroup背景设置为白色
将以下行添加到您的RadioGroup
android:background="@android:color/white"编辑:在这里,使用您提供的xml代码,一切都很好。但是Thread.sleep(500)会暂停你的主线程半秒。相反,请使用
`handler.postDelayed(runnable, delayInMillis);` 另外,我怀疑您的样式已被修改(colorPrimary、colorAccent等)。请检查一下
https://stackoverflow.com/questions/57253522
复制相似问题