Boldbayar
Boldbayar

Reputation: 875

Android compare Button with Textview value

Hell i am trying to compare textview value with button how can i do it?

i tried this way but not working.

button xml - android:tag = "1"

Java

Button btn = (Button) findViewById(id); 
string valu = btn.getTag();
string txt = textView.getText();

if(txt.equals(valu))
{
// do what you want
}

Upvotes: 0

Views: 493

Answers (2)

Piyush
Piyush

Reputation: 18933

Simply use this.

if (b.getTag().toString().equalsIgnoreCase(tv.getText().toString())) {

   Toast.makeText(getApplicationContext(), "HI", 9000).show();
}

Upvotes: 1

nano_nano
nano_nano

Reputation: 12523

try this:

textView.getText().toString();

getText() returns a CharSequence not a String. Because of that your equals must be false.

Upvotes: 1

Related Questions