-5

i am write this code for my android app.

    btn =(Button)findViewById(R.id.button);
    et =(EditText)findViewById(R.id.editText);
    tv =(TextView)findViewById(R.id.textView);

    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String name =et.getText().toString();
            String a = "a";
            String a1 = "a";
            String b = "b";
            String b1 = "ß";
            if(name.equals(a)){
             tv.setText(a1);

            }
            else if (name.equals(b)){
                tv.setText(b1);

            }
        }
    });

}

}

and write a in edit text don't show a in text view and write b in edit text don't show ß in text view please help

p.karimdost
  • 263
  • 1
  • 2
  • 8
  • 8
    [How do I compare strings in Java?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Ravi Jul 01 '16 at 07:43

3 Answers3

1

== is used to compare equality of two objects i.e, their name and hashcode. Use equals or equalsIgnoreCase

name.equals("A")

or

name.equalsIgnoreCase("A")
Boola
  • 358
  • 3
  • 14
0
if (name.equals("A")){
    tv.setText("example");
}
Ravi
  • 34,851
  • 21
  • 122
  • 183
Kirill V.
  • 67
  • 6
0

Simply use

if(name.equalsIgnoreCase("A")) {
   tv.setText("example");
}
sam
  • 128
  • 9