开发者

How to dsiplay dialog to log in or cancel?

When a button is clicked.

I want to test a shared preference to see if something exists.

If so, then i want it to launch the activity.

If not i woul开发者_Go百科d like it to Display a Dialog. with two buttons to log in or cancel.

When the log in button is clicked i would like to launch a activity.

I am familiar with testing the SharedPreference.

Just need a little guidence on AlertDialog and how to display the login and cancle buttons.


Here is the code for the 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();


See this code for alert dialog

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜