Hi Andre

I assume that buton 3-6 are in R.layout.poput_new and not
R.layout.main, in that case you call findViewById on the activity
which does not contain those buttons. You need to call findViewById on
the dialog after you called setContentView.

Try the following:

in onCreate:
remove the following lines
           button3 = (Button) findViewById(R.id.button3);
           button4 = (Button) findViewById(R.id.button4);
           button5 = (Button) findViewById(R.id.button5);
           button6 = (Button) findViewById(R.id.button5); // typo at
this line, should probably be R.id.button6

in onCreateDialog:
add the following lined just before "button3.setOnClickListener(this);"
           button3 = (Button) dialog.findViewById(R.id.button3);
           button4 = (Button) dialog.findViewById(R.id.button4);
           button5 = (Button) dialog.findViewById(R.id.button5);
           button6 = (Button) dialog.findViewById(R.id.button6);

Cheers,
Chrigi

On Wed, Feb 10, 2010 at 1:28 PM, André <pha...@hotmail.com> wrote:
> Hello,
>
> I am trying to use 6 buttons in one activity. The first 2 buttons
> work, but the problem is the 4 other ones that are located in a dialog
> box. For the first two buttons I use
> "button1.setOnClickListener(this);" which is placed in the oncreate
> method. For the other 4 buttons I thought I could use the same line
> but place it in the Dialog method. But I was wrong. I this it's the
> (this) that is wrong. Bellow is my code and I have marked the line
> where eclipse debug reacts. Or maybe you pro's see some thing else
> that I did totally wrong?
>
> regards
> André
>
> ...
> public class ButtonTest1 extends Activity implements OnClickListener {
>        static final int DIALOG_NEW = 0;
>        private Button button1;
>        private Button button2;
>        private Button button3;
>        private Button button4;
>        private Button button5;
>        private Button button6;
>
>
>
>    /** Called when the activity is first created. */
>   �...@override
>    public void onCreate(Bundle savedInstanceState) {
>        super.onCreate(savedInstanceState);
>        setContentView(R.layout.main);
>            button1 = (Button) findViewById(R.id.button1);
>            button2 = (Button) findViewById(R.id.button2);
>            button3 = (Button) findViewById(R.id.button3);
>            button4 = (Button) findViewById(R.id.button4);
>            button5 = (Button) findViewById(R.id.button5);
>            button6 = (Button) findViewById(R.id.button5);
>
>        button1.setOnClickListener(this);
>        button2.setOnClickListener(this);
>
>    }
>    public void onClick(View view) {
>        switch (view.getId()) {
>                case R.id.button1:
>                        showDialog(DIALOG1);
>                break;
>                case R.id.button2:
>
>                break;
>                case R.id.button3:
>
>                    break;
>                case R.id.button4:
>
>                    break;
>                case R.id.button5:
>
>                    break;
>                case R.id.button6:
>
>                    break;
>        }
>    }
>    protected Dialog onCreateDialog(int id) {
>        Dialog dialog = new Dialog(this);
>        switch(id) {
>        case DIALOG_NEW:
>                dialog.setContentView(R.layout.popup_new);
>                dialog.setTitle("Choose button...");
>
>            button3.setOnClickListener(this);
> <------------------------------------------------------problem starts
> here when dialog box opens
>            button4.setOnClickListener(this);
>            button5.setOnClickListener(this);
>            button6.setOnClickListener(this);
>
>            break;
>
>        default:
>            dialog = null;
>        }
>        return dialog;
>    }
> ...
>
> --
> 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+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to