【发布时间】:2016-05-10 00:33:12
【问题描述】:
我的 GPSTracker 中有这个方法:
public void showSettingsAlert() {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(myContext);
// Setting Dialog Title
alertDialog.setTitle("GPS Settings");
// Setting Dialog Message
alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");
// Setting Icon to Dialog
// alertDialog.setIcon(R.drawable.delete);
// On pressing Settings button
alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
myContext.startActivity(intent);
}
});
// on pressing cancel button
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
}
当我运行它时,我会不断地同时出现 10 个对话框,所以基本上我可以按 10 次取消或类似的东西,我该如何解决? 我读到了
final AlertDialog alert = alertDialog.create();
if(alert.isShowing()) {
alert.dismiss();
}
else {
alert.show();
}
但这对我不起作用,我仍然有多个对话...有人可以帮帮我吗?基本上我在打电话 if(gps.isEnabled()) gps.showSettingsAlert();在我的活动中。
if (itemsArrayList.get(position).getCoordinates() == null || !gps.canGetLocation()) {
holder.distance.setText("Distance not available");
gps.showSettingsAlert();
}
【问题讨论】:
-
请发布更多您的代码。到目前为止您发布的代码没有任何问题,因此问题出在其他地方。如果您发布更多代码,它将使某人更容易识别问题。
-
张贴你的电话
showSettingsAlert的代码 -
我添加了调用 showSettingsAlert 的代码。
标签: android dialog gps android-alertdialog