开发者

alert dialog not appearing in 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开发者_如何学JAVA("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();
            }
    }
}

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜