我希望按钮仅在内容等于 America 时打开对话框。我该怎么做?我尝试创建一个对话框活动,然后使用一个意图我得到了对话框,但它是单独出现的,而不是当前活动!
if(check.contentEquals("america")){
// Then I want the dialog to open here
尝试这个:
if(check.contentEquals("america")){
imageview.setAlpha(0);
Intent i = new Intent(ACTION NAME);
startActivity(i);
}
如果你想运行一个简单的对话框,你所要做的就是:
if(check.contentEquals("america")){
imageview.setAlpha(0);
mDialog.show();
}
显示警报对话框试试这个:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle("Title");
builder.setMessage("your message");
builder.setInverseBackgroundForced(true);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
final AlertDialog alert = builder.create();
if(check.contentEquals("america")){
alert.show();
}