Reputation: 1749
I have this code :
@OnClick( {R.id.iv_first,R.id.iv_second} )
public void launchCards() {
Log.i(TAG,"clicked");
}
Is there a way to know inside the launchCards()
method which of the two ImageView
has been clicked ?
Upvotes: 3
Views: 525
Reputation: 4182
You can do something like this:
@OnClick({R.id.iv_first,R.id.iv_second})
public void launchCards(View view) {
// Check which ImageView was clicked
switch (view.getId()) {
case R.id.iv_first:
// 1 clicked
break;
case R.id.iv_second:
// 2 clicked
break;
}
}
Upvotes: 7
Reputation: 659
Maybe reading the documentation at http://jakewharton.github.io/butterknife/ wouldn't hurt - just change your method signature to launchCards(View v)
and then use v.getId()
inside your function.
Hope this helps you, comment if you have any questions
Upvotes: 0