单击按钮时。
我想测试共享首选项以查看是否存在某些内容。
如果是,那么我希望它能够启动活动。
如果不是我想要显示对话框。用两个按钮登录或取消。
点击登录按钮后,我想发起一项活动。
我熟悉测试SharedPreference。
只需要对AlertDialog有一点指导,以及如何显示登录和cancle按钮。
答案 0 :(得分:1)
以下是AlertDialog的代码:
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
alt_bld.setMessage("Do you want to login or cancel?")
.setCancelable(false)
.setPositiveButton("Login", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Login' Button
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Cancel' Button
dialog.cancel();
}
});
AlertDialog alert = alt_bld.create();
// Title for AlertDialog
alert.setTitle("Title");
// Icon for AlertDialog
alert.setIcon(R.drawable.icon);
alert.show();
答案 1 :(得分:0)
请参阅此代码以获取警告对话框
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("Login")
.setPositiveButton("Login", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
//validate and check login
}
}
)
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
//Do nothing
}
});
builder.show();