-2

I have this code,

String mString = edt_i.getText().toString().substring(0,3);

if (mString == "VIP" || mString == "MEM"){
    checkif();
}
else {
    Toast.makeText(MainActivity.this,"Mã "+edt_i.getText().toString()+" không hợp lệ",
            Toast.LENGTH_SHORT).show();
}                           

After I get substring "VIP" or "MEM", I compare if it is "VIP" or "MEM", if it true, start checkif() method.

Please help me!

Nam Jayer
  • 19
  • 7
  • `==` operator compares primitive data values, not objects. Use the `equals()` or `equalsIgnoreCase()` method to compare strings instead. – progyammer Sep 21 '16 at 07:07

1 Answers1

2

if (mString == "VIP" || mString == "MEM"){ checkif(); }

replace this with

if (mString.equals("VIP" )|| mString.equals"MEM"){
                checkif();
            }

For comparing strings use equals or equalsIgnoreCase method not ==.

Preetika Kaur
  • 1,991
  • 2
  • 16
  • 23