Friday, April 30, 2010

[android-developers] One clicklistener for many buttons.

Dear all,
I'm implementing an app that has 12 buttons placed in a
grid. When one is pressed, the number that the button displays
(through button.getText()) has to be retrieved and passed to a common
method. I've gone down the route of implementing OnClickListener e.g.
public class WordRecall extends Activity implements OnClickListener

and then overriding public void onClick(View v) to handle events.
However, what I want to avoid is having to repeat the following lines
12 times :

Button btn4Button = (Button)findViewById(;

Is there a way in Android 1.5 of avoiding this as there is in 1.6?

Am I better off using 1.6 for development instead of 1.5?



You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment