0
我是Xamarin新手。我有以下的對話片段:Xamarin。如何在循環中顯示對話框?
public class EnableGpsDialog : DialogFragment
{
public static EnableGpsDialog newInstance()
{
EnableGpsDialog d = new EnableGpsDialog();
return d;
}
override public Dialog OnCreateDialog(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var builder = new AlertDialog.Builder(Activity);
var title = "Please, enable GPS";
builder.SetTitle(title);
builder.SetPositiveButton("OK", EnableGpsAction);
var dialog = builder.Create();
dialog.SetCanceledOnTouchOutside(false);
return dialog;
}
private void EnableGpsAction(object sender, DialogClickEventArgs e)
{
var intent = new Intent(Android.Provider.Settings.ActionLocationSourceSettings);
StartActivity(intent);
}
}
它運作良好,但我需要這個對話框,而GPS是禁用顯示。 我該如何做到這一點? 我的方法(它顯示什麼):
private void EnableGps()
{
LocationManager locationManager = null;
while (true)
{
locationManager = (LocationManager)GetSystemService(Context.LocationService);
if (locationManager.IsProviderEnabled(LocationManager.GpsProvider))
{
return;//gps is enabled
}
else
{
//show dialog
EnableGpsDialog gpsDialog = new EnableGpsDialog();
var transaction = FragmentManager.BeginTransaction();
gpsDialog.Show(transaction, "Enable GPS dialog fragment");
}
}
}