Venky
Venky

Reputation: 2047

Not able to create a Dialog in Android

I'm not sure what's wrong, I'm working on Xamarin Android and I'm trying to create a new dialog by

Dialog customdialogBuilder = new Dialog(Android.App.Application.Context);

added a debugger to the above line, as soon as I press F10 to jump to the next line, it says unhandled exception, no clue what am I doing wrong in this.

any inputs would be helpful

Upvotes: 0

Views: 189

Answers (2)

Kuls
Kuls

Reputation: 2067

As far I know you are passing Application's context while creating object of Dialog, You need to pass Activity's context

Try as below,

Dialog customdialogBuilder = new Dialog(this);

Upvotes: 1

Harshad Pansuriya
Harshad Pansuriya

Reputation: 20910

you can create Dialog by giving application Context below way

Android.App.AlertDialog.Builder dialog = new AlertDialog.Builder(this);  
AlertDialog alert = dialog.Create();  
alert.SetTitle("Title");  
alert.SetMessage("Simple Alert");  
alert.SetButton("OK", (c, ev) =>  
{  
// Ok button click task  
});  
alert.Show();

Upvotes: 0

Related Questions