Two exact same apps, but one works, the other one doesn´t

Viewed 35

I have a demo app -where I figure out how to wright the code for my real app- and the real app. I want an ImageView called deck in the demo and deck1 in the real app to be replaced by a different drawable under certain conditions. In both apps these conditions are fulfilled, but in my demo app the Image changes and in my real app it doesn't. Also in both apps the exact same drawable is in my Drawable Files (Yes, in both app folders).

Code demo app:

deck = b.findViewById(R.id.imageView);
        deck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String standardWert= "Radler";
                Bundle karteAusgewähltFinal = getArguments();
                final String radlerWert = karteAusgewähltFinal.getString("2");
                    if (radlerWert == standardWert) {
                        deck.setBackgroundResource(R.drawable.radler_klein_level_1);}
                    else {

                    };}
                }
            );

        return b;
    }
}

and real app:

deck1 = v.findViewById(R.id.deck_karte_1);
        deck1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String wertIfCardIsChoosed = "Radler";
                Bundle karteAusgewähltFinal = getArguments();
                final String radlerWert = karteAusgewähltFinal.getString("2");
                    if (radlerWert == wertIfCardIsChoosed) {
                        deck1.setBackgroundResource(R.drawable.radler_klein_level_1);}
                    else {

                    };}
        });

        return v;

    }
}

My debugger also shows that the condition is fulfilled enter image description here

I don´t know what's the difference between these apps, maybe you can find the reason, I would be really happy since I am trying to figure that out for the past 5 hours.

Edit: XML file Real App:

<ImageView
            android:id="@+id/deck_karte_1"
            android:layout_width="102dp"
            android:layout_height="102dp"
            android:clickable="true"
            android:adjustViewBounds="true"
            app:layout_constraintBottom_toBottomOf="@+id/deck_karte_1_hintergund"
            app:layout_constraintEnd_toEndOf="@+id/deck_karte_1_hintergund"
            app:layout_constraintStart_toStartOf="@+id/deck_karte_1_hintergund"
            app:layout_constraintTop_toTopOf="@+id/deck_karte_1_hintergund"
            app:srcCompat="@drawable/buttondeckcardclick" />

XML file demo App:

<ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="358dp"
            android:background="@drawable/deck_karten_hintergrund"
            android:clickable="true"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
1 Answers

I've found your ImageView has srcCompat property in real app.
I supposed background of your ImageView will be hided by Foreground of your ImageView.

So I suggest that you test after remove srcCompat property.

    <ImageView
        android:id="@+id/deck_karte_1"
        android:layout_width="102dp"
        android:layout_height="102dp"
        android:clickable="true"
        android:adjustViewBounds="true"
        app:layout_constraintBottom_toBottomOf="@+id/deck_karte_1_hintergund"
        app:layout_constraintEnd_toEndOf="@+id/deck_karte_1_hintergund"
        app:layout_constraintStart_toStartOf="@+id/deck_karte_1_hintergund"
        app:layout_constraintTop_toTopOf="@+id/deck_karte_1_hintergund" />
Related