setPositiveButton() is for setting the button text and listener. To use findViewById, you need to set your own custom layout, but this won't work with AlertDialog.Builder (iirc), you need to use the Dialog class. Here is some code I use for this in my application:
mDialog = new Dialog(this); mDialog.setCancelable(true); mDialog.setContentView(R.layout.dialoginput); //set the custom layout mBtn_DialogOK = (Button) mDialog.findViewById(R.id.btn_ok); //From our custom layout mBtn_DialogOK.setTag(BUTTON_OK_ID); mBtn_DialogOK.setOnClickListener(this); Also, findViewById is for R.id.<id of view>, not for Strings. On Feb 5, 7:35 am, Lucius Fox <lucius.fo...@gmail.com> wrote: > Hi, > > I create a dialog using this: > > Dialog d = new AlertDialog.Builder(MyActivity.this) > .setPositiveButton(R.string.btn_yes, new > DialogInterface.OnClickListener() { > public void onClick(DialogInterface dialog, int > whichButton) { > dummy(); > } > }) > > Then I try to get the 'yes' button using this: > Button yesButton = (Button)d.findViewById(R.string.btn_yes); > > But I get null for my 'yesButton'. > > Any idea why findViewById does not work? And if not, how can I get a > reference to yes button of the dialog? > > Thank you. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---