[英]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("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登錄頁面的代碼,當我輸入單擊登錄按鈕時,將顯示progressdialog,並且如果用戶名或密碼不正確,則必須顯示該警報框,但不會顯示該警報。
那么線程或其他方面有什么問題嗎? 請幫我
您不能在另一個對話框之上顯示第二個對話框。
您一次只能在一個活動的頂部顯示一個對話框。
您可以做的是,在登錄視圖上設置錯誤消息,然后關閉進度對話框,而在關閉該對話框時,用戶將看到出現了問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.