[android-developers] Re: How to use findViewById() in a dialog
Thanks for sharing this info. On Thu, Feb 5, 2009 at 2:57 PM, Emmanuel wrote: > > On last note : > > I finally found the Id of this button : android.R.id.button1. > here's my try (succesfull ): > public void onClick(DialogInterface dialog, int whichButton) > { > Dialog curDialog = (Dialog) dialog; >Button curButton = (Button) curDialog.findViewById > ( android.R.id.button1 ); >curButton.setText("Coucou"); > } > > Emmanuel > http://androidblogger.blogspot.com/ > > > > On Feb 5, 9:09 pm, Emmanuel wrote: > > R.string.btn_yes is the string that appear on your button. > > Not the id ! > > > > findVienwById wants an id ! > > > > Emmanuelhttp://androidblogger.blogspot.com/ > > > > On Feb 5, 8:35 am, Lucius Fox 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 -~--~~~~--~~--~--~---
[android-developers] Re: How to use findViewById() in a dialog
On last note : I finally found the Id of this button : android.R.id.button1. here's my try (succesfull ): public void onClick(DialogInterface dialog, int whichButton) { Dialog curDialog = (Dialog) dialog; Button curButton = (Button) curDialog.findViewById ( android.R.id.button1 ); curButton.setText("Coucou"); } Emmanuel http://androidblogger.blogspot.com/ On Feb 5, 9:09 pm, Emmanuel wrote: > R.string.btn_yes is the string that appear on your button. > Not the id ! > > findVienwById wants an id ! > > Emmanuelhttp://androidblogger.blogspot.com/ > > On Feb 5, 8:35 am, Lucius Fox 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 -~--~~~~--~~--~--~---
[android-developers] Re: How to use findViewById() in a dialog
R.string.btn_yes is the string that appear on your button. Not the id ! findVienwById wants an id ! Emmanuel http://androidblogger.blogspot.com/ On Feb 5, 8:35 am, Lucius Fox 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 -~--~~~~--~~--~--~---
[android-developers] Re: How to use findViewById() in a dialog
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., not for Strings. On Feb 5, 7:35 am, Lucius Fox 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 -~--~~~~--~~--~--~---