Ich habe Kontrollkästchen Code in einer CardView-Layout-Datei. Die CardView hat einen weißen Hintergrund. Normalerweise denke ich, dass die ungeprüfte Checkbox ein schwarzes Quadrat ist. Mein Layout zeigt kein leeres Kontrollkästchen. Alles, was ich sehe, ist nur der weiße CardView-Hintergrund (oben CardView im Screenshot). Wenn ich auf den am weitesten rechts liegenden Bereich der CardView klicke, wo der Checkbox-Code formatiert ist, erscheint eine grüne Checkbox (untere CardView im Screenshot). Was fehlt mir hier? .Android: Warum zeigt Checkbox kein leeres Kontrollkästchen für den deaktivierten Status an?
Layout-Datei:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/background4main" >
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/singlecard_view1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="@android:color/white"
card_view:cardCornerRadius="6dp"
android:orientation="horizontal"
android:layout_margin="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:selectableItemBackground" >
<TextView
android:id="@+id/cardBlankText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="todo"
android:textStyle="bold"
android:textColor="@android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="20sp" />
<TextView
android:id="@+id/cardBlankText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/cardBlankText2"
android:text="note1"
android:textStyle="bold"
android:textColor="@android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="20sp" />
<CheckBox
android:id="@+id/chkSelected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Adapter file:
...
public class ListViewHolder extends RecyclerView.ViewHolder {
TextView cardBlankText2;
TextView cardBlankText3;
CheckBox chkSelected;
public ListViewHolder(View itemView) {
super(itemView);
cardBlankText2 = (TextView)itemView.findViewById(R.id.cardBlankText2);
cardBlankText3 = (TextView)itemView.findViewById(R.id.cardBlankText3);
chkSelected = (CheckBox) itemView.findViewById(R.id.chkSelected);
}
...
@Override
public void onBindViewHolder(final ListViewHolder holder, final int position) {
holder.cardBlankText2.setText(dbList.get(position).getTodo());
holder.cardBlankText3.setText(dbList.get(position).getNote1());
holder.chkSelected.setChecked(dbList.get(position).isSelected());
holder.chkSelected.setTag(dbList.get(position));
}
Post Java-Code –
ok wird nun hinzufügen. – AJW
Was passiert, wenn Sie das gleiche Kontrollkästchen deaktivieren? Wird es wieder wie der erste Screenshot angezeigt? –