This question already has an answer here:
- How do I compare strings in Java? 23 answers
I'm currently working on displaying image on ImageView via If/Else Statement, I need help on displaying via if else, the problem is it is always showing the first one.
JAVA
greetingTextView = (TextView) findViewById(R.id.greeting_text_view);
totpoints = (TextView) findViewById(R.id.au_tpresult);
totshare = (TextView) findViewById(R.id.au_tsresult);
btnLogOut = (Button) findViewById(R.id.logout_button);
cardshow = (ImageView) findViewById(R.id.card_stack);
Intent intent = getIntent();
String user = intent.getStringExtra("fullname");
String user1 = intent.getStringExtra("totalpoints");
String user2 = intent.getStringExtra("totalshare");
String user3 = intent.getStringExtra("cardtype_id");
greetingTextView.setText(user);
totpoints.setText(user1);
totshare.setText(user2);
if (user3 == "0" {
((ImageView) findViewById(R.id.card_stack)).setImageResource(R.drawable.thar_silver);
} else if (user3 == "1") {
((ImageView) findViewById(R.id.card_stack)).setImageResource(R.drawable.thar_gold);
} else if (user3 == "2") {
((ImageView) findViewById(R.id.card_stack)).setImageResource(R.drawable.thar_uaeu);
}
cardtype_id from database returning = "0", "1" or "2"
XML
<ImageView
android:id="@+id/card_stack"
android:layout_gravity="center_horizontal"
android:layout_width="407dp"
android:layout_height="230dp"
android:layout_marginTop="10dp"
app:srcCompat="@drawable/thar_silver"
android:layout_weight="0.73" />
Thank you in advance!
Aucun commentaire:
Enregistrer un commentaire