首页 > 解决方案 > 智能手机上没有复选标记的 Android 复选框(模拟器正在工作)

问题描述

我有一些无法正常工作的复选框。复选框结果已选中,但没有复选标记。如果单击复选框两次,将出现复选标记。在模拟器上没有问题,但在我的 Galaxy S7 (Oreo) 上有这个错误。从 db 加载数据后,以编程方式检查复选框:

    @Override
    protected void onPostExecute(Boolean successo) {
        pbGestioneProfilo.setVisibility(View.GONE);
        if (successo) {
            passioniET.setText(passioni);
            libriET.setText(libri);
            filmserieET.setText(filmserie);
            negoziET.setText(negozi);
            tecnologiaCB.setChecked(tecnologia.equals(Utils.TRUE) ? true : false);
            sportCB.setChecked(sport.equals(Utils.TRUE) ? true : false);
            viaggiCB.setChecked(viaggi.equals(Utils.TRUE) ? true : false);
            casacucinaCB.setChecked(casacucina.equals(Utils.TRUE) ? true : false);
            abbigliamentoCB.setChecked(abbigliamento.equals(Utils.TRUE) ? true : false);
            if (!urlProfilo.equals("")) {
                Glide.with(getContext())
                        .load(urlProfilo)
                        .into(imgprofilo);
            }
        } else {
            Log.d("MYTAG","ERROR");
            Toast.makeText(getContext(),"Error",Toast.LENGTH_SHORT).show();
        }
    }

在 xml 上:

<ScrollView
    android:background="@drawable/backgroundtab"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fbutton="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">


<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

...

    <CheckBox
        android:id="@+id/tecnologiaCB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginTop="8dp"
        android:text="Tecnologia"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/interessiTV" />

    <CheckBox
        android:id="@+id/sportCB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:text="Sport"
        app:layout_constraintBaseline_toBaselineOf="@+id/tecnologiaCB"
        app:layout_constraintStart_toEndOf="@+id/tecnologiaCB" />

    <CheckBox
        android:id="@+id/viaggiCB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:text="Viaggi"
        app:layout_constraintBaseline_toBaselineOf="@+id/tecnologiaCB"
        app:layout_constraintStart_toEndOf="@+id/sportCB" />

    <CheckBox
        android:id="@+id/casacucinaCB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Casa e Cucina"
        app:layout_constraintStart_toStartOf="@+id/tecnologiaCB"
        app:layout_constraintTop_toBottomOf="@+id/tecnologiaCB" />

    <CheckBox
        android:id="@+id/abbigliamentoCB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Abbigliamento"
        app:layout_constraintBaseline_toBaselineOf="@+id/casacucinaCB"
        app:layout_constraintStart_toStartOf="@+id/sportCB" />

</androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>

有可能修复吗?谢谢

在此处输入图像描述

标签: androidcheckboxandroid-emulator

解决方案


推荐阅读