在Android中没有出现警告对话框 [英] alert dialog not appearing in android

查看:114
本文介绍了在Android中没有出现警告对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class BabyName extends Activity implements View.OnClickListener, Runnable{
    /** Called when the activity is first created. */

    Login loginclass=new Login();
    ProgressDialog dialog;

    Thread t=new Thread(this, "sample");

     AlertDialog al;
     long id;
     boolean flg=false;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);        
        Button launch=(Button)findViewById(R.id.login_button);
        launch.setOnClickListener(this);
    }

    public void onClick(View viewparam){
        EditText username=(EditText)findViewById(R.id.txt_username);
        EditText password=(EditText)findViewById(R.id.txt_password);

        String sUserName = username.getText().toString();
        String sPassword = password.getText().toString();


            dialog=ProgressDialog.show(BabyName.this, "", "Please wait for few seconds...", true);

            loginclass.setId(sUserName);
            loginclass.setPassword(sPassword);     
            al=new AlertDialog.Builder(this).create();
            id=t.getId();                
            t.start();          
            message();


    }
    public void run(){    
            Get_Data getdata=new Get_Data();        
            getdata.logincheck(loginclass);
            dialog.dismiss();       
    }

    public void message(){

        if(loginclass.getStatus().trim().equals("true")){           
            dialog.dismiss();
            /*  Intent i = new Intent(BabyNames.this, ChoiceActivity.class);
                startActivityForResult(i, SUB_ACTIVITY_REQUEST_CODE);*/
            }else if(loginclass.getStatus().trim().equals("false")){

                al.setTitle("Error");
                al.setMessage("Username or password incorrect!!");
                al.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      return;
                  } }); 
                al.show();
            }else {

                //al=new AlertDialog.Builder(this).create();
                al.setTitle("Http Error");
                al.setMessage("Not Connected");
                al.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      return;
                  } }); 
                al.show();
            }
    }
}

这是android的登录页面的code和当我进入点击登录按钮progressdialog出现和alertbox后一定要当用户名或密码不正确显示,但它没有显示该警报。

This is the code of login page of android and when i enter click login button the progressdialog appears and after that alertbox must be shown if username or password incorrect but it is not showing that alert.

所以有在线程或别的东西什么问题?
请大家帮我

so is there any problem in threading or something else? please help me

推荐答案

您不能显示在另一个对话框顶部的第二个对话框。

You can't show a second dialog on top of another dialog.

您只能说明有一个是在上的活动之上的时间对话框。

You can only show one dialog at a time on top of an activity.

你能做什么,被设置在登录查看错误信息,然后关闭该进程对话框,当被驳回用户将看到出事了。

What you can do, is set the error message on the login view, then dismiss the progress dialog, and when that is dismissed the user will see something went wrong.

这篇关于在Android中没有出现警告对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆