AlertDialog 出现在模拟器中但未出现在 phone
AlertDialog showing up in emulator but not in phone
我是一个糟糕的程序员,但我设法将我的同事用来简化他们日常工作的应用程序整合在一起。我现在被要求放入一个对话框。就像我一直做的那样,我在互联网上搜索了很长时间,并且或多或少地偷了一个解决方案。我在尝试模拟器时取得了巨大的成功。但是,当我的同事 phone 更新应用程序时,它不起作用 - 该应用程序仍然可以正常工作,但没有显示对话框。
我的猜测是,这与设备的 API 级别有关。但根据我的研究,AlertDialog 在很长一段时间内都是一种有效的方法。我需要对话框以 phone 显示 android 版本 4.1.2.
以下是我的代码,希望这是一个简单的错误,或者有人可以帮助我提供其他解决方案。我没有收到任何错误。
非常感谢!
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
showUrl = "http://randomurl.php";
break;
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(Main2Activity.this);
builder.setMessage("Yes or No?").setPositiveButton("yes", dialogClickListener)
.setNegativeButton("no", dialogClickListener).show();
AlertDialog.Builder alertDialog = new AlertDialog.Builder(RecordActivity.this);
// Setting Dialog Message
alertDialog.setMessage("alert_message"));
// Setting Positive "Yes" Button
alertDialog.setPositiveButton("Click Here", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(RecordActivity.this, PurchaseActivity.class);
startActivityForResult(i, RESULT_ACTIVITY_PURCHASE);
dialog.dismiss();
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
// Showing Alert Message
alertDialog.show();
我是一个糟糕的程序员,但我设法将我的同事用来简化他们日常工作的应用程序整合在一起。我现在被要求放入一个对话框。就像我一直做的那样,我在互联网上搜索了很长时间,并且或多或少地偷了一个解决方案。我在尝试模拟器时取得了巨大的成功。但是,当我的同事 phone 更新应用程序时,它不起作用 - 该应用程序仍然可以正常工作,但没有显示对话框。
我的猜测是,这与设备的 API 级别有关。但根据我的研究,AlertDialog 在很长一段时间内都是一种有效的方法。我需要对话框以 phone 显示 android 版本 4.1.2.
以下是我的代码,希望这是一个简单的错误,或者有人可以帮助我提供其他解决方案。我没有收到任何错误。
非常感谢!
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
showUrl = "http://randomurl.php";
break;
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(Main2Activity.this);
builder.setMessage("Yes or No?").setPositiveButton("yes", dialogClickListener)
.setNegativeButton("no", dialogClickListener).show();
AlertDialog.Builder alertDialog = new AlertDialog.Builder(RecordActivity.this);
// Setting Dialog Message
alertDialog.setMessage("alert_message"));
// Setting Positive "Yes" Button
alertDialog.setPositiveButton("Click Here", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(RecordActivity.this, PurchaseActivity.class);
startActivityForResult(i, RESULT_ACTIVITY_PURCHASE);
dialog.dismiss();
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
// Showing Alert Message
alertDialog.show();