Cuadro de diálogo personalizado de Android con botón

Very simple question today. When I attempt to retreive a reference to the button on the dialog I always receive a null value.

public void onRestart() {

    //must prompt with modal dialog for pin
    Dialog dialog = new Dialog(this);

    //check pin
    //set view to enterpin XML screen
    //register button

    //show dialog;
    //listen for button being clicked
    Button button = (Button) findViewById(;
    button.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
            EditText editText = (EditText) findViewById(;
            int enteredPin = Integer.parseInt(editText.getText().toString());
            SharedPreferences sharedP = getPreferences(MODE_PRIVATE);
            int temp = sharedP.getInt("pin", 0);
                pinCheck = true;
                pinCheck = false;


Yes the button exists, no I did not mispell it's reference. Yes I've cleaned the project and restarted eclipse. How can the button not be associated with the view when i clearly called setContentView()? I'm sure it's simple, I've never used dialogs before, new to GUI in general. Especially Android

preguntado el 12 de junio de 12 a las 14:06

1 Respuestas

Button button = (Button)dialog.findViewById(;

When you show Dialog ,you have to give refrences of dialog.because without it ,Button refrences from main.xml.i mean from main view setContentView(R.layout.main);.

Respondido el 12 de junio de 12 a las 14:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.