我正在嘗試創建一個警告對話框,但是當我運行我的應用程序時它不會顯示。這裏是我的代碼:Android應用程序中的AlertDialog不顯示
final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage("Your GPS seems to be disabled, do you want to enable it?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
dialog.cancel();
buildLocationMessage();
}
});
final AlertDialog alert = builder.create();
alert.show();
仍然一無所獲。我也收到一個警告,表示方法setButton已被棄用。 –