Hi I have something like this (3 buttons) in my activity xml pointing to same method:
<Button
android:id="@+id/Button_1"
android:onClick="printNo"
android:text="@string/Button_1" />
<Button
android:id="@+id/Button_2"
android:onClick="printNo"
android:text="@string/Button_2" />
<Button
android:id="@+id/Button_3"
android:onClick="printNo"
android:text="@string/Button_3" />
Is there any way I could determine which button was pressed while in the printNo method ?
public void printNo( View v ) {
switch (v.getId()) {
case (R.id.Button_1):
//stuff
break;
case (R.id.Button_2):
//stuff
break;
case (R.id.Button_3):
//stuff
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With