Thanks Mark,

I am completely new to java so please bare with me. This is what i have that
seems to work but i have to create a new listener for each button(currently
i only have one as you see below)
I couldnt get your method to work. can you tell me what im doing wrong?

package com.joshuadobbs.testing;
import android.app.Activity;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class PegLites extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn1=(Button) findViewById(R.string.btn1);
        Button btn2=(Button) findViewById(R.string.btn2);
        Button btn3=(Button) findViewById(R.string.btn3);
        btn1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {

            }

        });

   }

}

Thanks,

Josh
On Sat, Dec 6, 2008 at 5:15 AM, Mark Murphy <[EMAIL PROTECTED]> wrote:

>
> Josh wrote:
> > is there a way to create multiple button controls dynamically and to
> > have the same listener handle all of them?
>
> Sure, the same general way you might do it in Swing or SWT:
>
> Button btn1=new Button(this);
> Button btn2=new Button(this);
> Button btn3=new Button(this);
>
> btn1.setOnClickListener(hitMe);
> btn2.setOnClickListener(hitMe);
> btn3.setOnClickListener(hitMe);
>
> View.OnClickListener hitMe=new View.OnClickListener() {
>        public void onClick(View v) {
>                // do something useful here
>        }
> });
>
> // add buttons to parent ViewGroup
>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com
> _The Busy Coder's Guide to Android Development_ Version 1.9 Available!
>
> >
>


-- 
cell: 714-588-4077  - feel free to send me txt msgs at this number
email: [EMAIL PROTECTED], [EMAIL PROTECTED]
Yahoo Messenger: [EMAIL PROTECTED]
AIM: JoshDFlexGuy
MSN: [EMAIL PROTECTED]
Google Talk: [EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to