user2976522
user2976522

Reputation: 47

Android onClick double method

I would like to know a simple thing. I have 2 methods, and if there is a TextView string "ok" the onClick event should call out method 1, however if the string in a TextView is "no" the onClick event should call the method 2. How can I do this? thanks

Upvotes: 1

Views: 59

Answers (1)

CChi
CChi

Reputation: 3134

You can use setTag on the textView. when onClick is fired. You can use getTag and cast it to a string and compare. Depending on the result, call different method

before you set a listener to your textview.

tv.setTag("ok");
tv2.setTag("no");

in your on click listener.

public void onClick(View v){
  String tag = (String) v.getTag();
  if (tag.equals("ok"){
    callMethod1();
  } else if (tag.equals("no")){
    callMethod2();
  }
}

Upvotes: 1

Related Questions