+ 1

I want to print something if(txt1="abc") textview value will be same as i given in string. But i always getting error.

Android Studio: (Java) Code are here.... m1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { txt1.setText(txt1.getText().toString()+"a"); m1.setEnabled(false); } }); m2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { txt1.setText(txt1.getText().toString()+"b"); m2.setEnabled(false); } }); m3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { txt1.setText(txt1.getText().toString()+"c"); m3.setEnabled(false); } }); m4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { txt1.setText(txt1.getText().toString()+"d"); m4.setEnabled(false); }

7th May 2020, 11:21 AM
Gorishankar
Gorishankar - avatar
4 Answers
+ 2
I think txt1 is text component then may be if(txt1.getText().equals("abc")) is you need.
7th May 2020, 12:04 PM
Jayakrishna 🇼🇳
0
You have to use double equality ==
7th May 2020, 11:24 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
0
Thanks Jayakrishna🇼🇳 It's Worked. I stuck in same from last 2 days.
7th May 2020, 12:16 PM
Gorishankar
Gorishankar - avatar
0
I'm glad that helped you.. Gorishankar You're welcome..
7th May 2020, 12:21 PM
Jayakrishna 🇼🇳