0

I want to declare AlertDialog.Builder outside OnCreate method of the activity class I want to use it in. If I wanted to use it in the activity I declare it in it's easy I just put in OnCreate method:

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);

But if I want it to be outside OnCreate method or the activity class I want to use it but in the same namespace or if I want it to be in another namespase or in another activity what do I have to put in the place of this keyword?

York Shen
  • 9,014
  • 1
  • 16
  • 40

1 Answers1

0

How to declare AlertDialog.Builder outside OnCreate method of the activity I want to use it in?(Xamarin.Android)

It needs a Context as its construction parameters, so give your AlertDialog a Context will solve this problem.

AlertDialog.Builder alertDialog = new AlertDialog.Builder(Android.App.Application.Context);

Furthermore, you could refer to: What is 'Context' on Android?

York Shen
  • 9,014
  • 1
  • 16
  • 40