[mono-android] Dialog Box Button click code?

Tomasz Cielecki tomasz at ostebaronen.dk
Tue Jun 26 17:02:06 UTC 2012


Have you tried using the dialogs FindViewById method?

i.e.

var button = (Button)dialog.FindViewById(Resource.Id.btnMonthSubtract);

If you are just using FindViewById in the activity, you won't find the
button as you are looking at the Activity Content View and not the
Dialog Content View. Then the button resolves to null and you get the
NullReferenceExceptions.

On Fri, Jun 22, 2012 at 6:55 AM, kailua <ivan at kailuaboy.com> wrote:
> I am having difficulty in tying to get my /dialog box button/ clickable. In
> fact, VS is throwing an exception.
>
> Here is the dialog box code I am using:
>
> Dialog dialog;
>            dialog = new Dialog(this);
>            dialog.SetContentView(Resource.Layout.dialog_items);
>            dialog.SetTitle("Refresh");
>            dialog.SetCancelable(true);
>            //Ok
>
>            var btnMonthS =
> FindViewById<Button>(Resource.Id.btnMonthSubtract);
>
> *//I have tried the following different button clicks. I see no guidance as
> to which one I should use.*
> btnMonthS.Click += (sender, e) =>
>  {
> //BUTTON CLICKED
> }
>
> btnMonthS.Click += delegate
> {
> //BUTTON CLICKED
> }
>
> *//BOTH OF THE ABOVE THROWS THE SAME EXCEPTION*
> *//E/mono    ( 1284): Unhandled Exception: System.NullReferenceException:
> Object reference not set to an instance of an object
> *
>
> Please let me know what simple code I need in order to execute the button.
>
> Thank you in advance.
>
> --
> View this message in context: http://mono-for-android.1047100.n5.nabble.com/Dialog-Box-Button-click-code-tp5710483.html
> Sent from the Mono for Android mailing list archive at Nabble.com.
> _______________________________________________
> Monodroid mailing list
> Monodroid at lists.ximian.com
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid



-- 
Med Venlig Hilsen / With Best Regards
Tomasz Cielecki
http://ostebaronen.dk


More information about the Monodroid mailing list