首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >选择不填充后的单选按钮

选择不填充后的单选按钮
EN

Stack Overflow用户
提问于 2019-07-29 20:05:05
回答 2查看 70关注 0票数 0

在android中,我编写了一个代码,用于在RadioGroup中显示user.answers ask questions,它有多个RadioButton,但是当用户单击一个RadioButton时,RadioButton不填充图形。radioGroup.setOnCheckedChangeListener的代码如下:

代码语言:javascript
运行
复制
    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如下:

代码语言:javascript
运行
复制
<?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>
EN

Stack Overflow用户

发布于 2019-07-29 20:25:06

这可能是因为背景的颜色和单选按钮的色调相同

尝试将RadioGroup背景设置为白色

将以下行添加到您的RadioGroup

代码语言:javascript
运行
复制
android:background="@android:color/white"

编辑:在这里,使用您提供的xml代码,一切都很好。但是Thread.sleep(500)会暂停你的主线程半秒。相反,请使用

代码语言:javascript
运行
复制
`handler.postDelayed(runnable, delayInMillis);`  

另外,我怀疑您的样式已被修改(colorPrimary、colorAccent等)。请检查一下

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57253522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档