Friday, April 30, 2010

[android-developers] Re: One clicklistener for many buttons.

you could do something like putting your ids in an array and putting
your discovered buttons in another array and then process them in a
loop.

Think about how SimpleCursorAdapter is doing what it does.

http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html

Take a look at the constructor.

On Apr 30, 9:46 am, "angushir...@googlemail.com"
<angushir...@yahoo.co.uk> wrote:
> 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 athttp://groups.google.com/group/android-developers?hl=en

--
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