I had the same problem of getButton() returning null. Just reorder the calls so that you show() the dialog before trying to access its buttons:
AlertDialog alertDialog = builder.create(); alertDialog.show(); Button button = (Button) alertDialog.getButton(BUTTON_POSITIVE); // edit the button size I'm not sure if you can then edit the button size after getting a reference to it, but this might be useful in the future. Cheers On Jun 8, 8:07 am, Thomas <[email protected]> wrote: > Anyone can help me? > > Thanks > > Thomas > > On 6/4/09, Thomas <[email protected]> wrote: > > > Hi All, > > > I need to build a AlertDialog with a short text ("A") and an OK > > Button. But if I use AlertDialog.Builder, the "ok" text button is not > > shown with a short text message. I tried to recover the Button object > > and set the layout to wrap_content. But when I try to use getButton > > function, it returns me null. > > > What Do I need to recover the button correctly and set the width as > > wrap_content? > > > Thanks all. > > > The code : > > > AlertDialog.Builder builder = new AlertDialog.Builder(this) > > .setPositiveButton("OK", > > mOKListener) > > .setMessage("A") > > .setCancelable(false); > > > AlertDialog alertDialog = builder.create(); > > Button button = (Button) alertDialog.getButton(BUTTON_POSITIVE); > > > // edit the button size > > > alertDialog.show(); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" 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-developers?hl=en -~----------~----~----~----~------~----~------~--~---

