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(R.id.fourWords);
btn4Button.setOnClickListener(this);

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?

Regards

Angus

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment