lundi 8 octobre 2018

If Else query in Java(Android) [duplicate]

This question already has an answer here:

I am facing some weird problems, its simple thing but I am not able to find out the catch.I am assigning a string value coming from other activity to string variable and printing it on the textview. now on If condition its going into else part not in success. can you please help me

Following is the code

  String x =bundle.getString("StatusCodeKey");
       String y =bundle.getString("TransactionTypeKey");

//These are TextView 
    tv_CustMobile.setText("Value of StatusCodeKey :" +x+"+");
        tv_Bc_Code.setText("Value of TransactionTypeKey :" +y+"+");

The output of these TextView's are

Value of TransactionTypeKey :Balance Inquiry+
Value of StatusCodeKey :001+

Both are in string. now I am using one IF statement. 


           if((x=="001") ){
               Toast.makeText(this, "Success Area for StatusCode", Toast.LENGTH_SHORT).show();

           }else{
               Toast.makeText(this, "Failed Area for StatusCode", Toast.LENGTH_SHORT).show();

           }

          if( (y=="Balance Inquiry")){
               Toast.makeText(this, "Success Area for TranKeyType", Toast.LENGTH_SHORT).show();

           }else{
               Toast.makeText(this, "Failed Area for TranKeyType", Toast.LENGTH_SHORT).show();
               Toast.makeText(this, "Value of  TranKeyType:"+y+":", Toast.LENGTH_SHORT).show();

           }

IN BOTH THE STATEMENTS ITS GOING IN ELSE OR FAILED AREA. NOT IN SUCCESS. 

I dont understand this minor thing. can someone please let me know why its not going to success . 

Aucun commentaire:

Enregistrer un commentaire