Android_Alert Message_Which不会关闭

时间:2011-03-08 06:04:42

标签: android

我正在尝试开发弹出消息框,向用户显示警告,不允许去任何地方(甚至不允许进入主屏幕/菜单)。

我正在尝试按下按钮,直到我按下该按钮并写入用户名和密码,这样用户就无法去任何地方。

我应该打断还是只是打电话给另一项活动?因为我想在完成第一项活动的任务后做上述事情,并且我想在下一次活动上做上面的流行事件。

1 个答案:

答案 0 :(得分:1)

创建一个创建弹出窗口的方法,如:

public void showAlert() {

        /* Layout that is shown inside the alert */
        LayoutInflater factory = LayoutInflater.from(mContext);

        //create a layout that is shown inside ur popup and give its name over here
        final View calibrateView = factory.inflate(your layout, null);

        EditText username = (EditText)calibrateView.findViewById(R.id.username);
        EditText password = (EditText)calibrateView.findViewById(R.id.password);

        /* Creating the popup */
        AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
        alert.setView(calibrateView);
        alert.setTitle(your title);
        alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {   

            public void onClick(DialogInterface dialog, int whichButton) {

                //check whether username and password is present over here.
                //if present give ur intent code for moving to the next activity
                //if absent, then create an alert showing the error msg
            }
         });

        alert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {            
            /* called when AlertDialog "Cancel" button is pressed.  */
            public void onClick(DialogInterface dialog, int whichButton) {
            }
        });

        alert.create();
        alert.show();
    }