當我創建兩個對話框,只有一個顯示了即使另一個條件爲真..如何在一個應用程序中使用兩個對話框?
下面的代碼
if (z<=18){
showDialog(1);
} else {
showDialog(3);
}
...................................................................................................................................................................
protected Dialog onCreateDialog(int id)
{
if (id== 1)
{
AlertDialog.Builder b=new AlertDialog.Builder(this);
b.setTitle("1st dialog");
b.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
AlertDialog d=b.create();
d.show();
}
else
{
AlertDialog.Builder b2=new AlertDialog.Builder(this);
b2.setTitle("2nd dialog ");
b2.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
AlertDialog dialoog=b2.create();
dialoog.show();
}
return super.onCreateDialog(id);
}
那麼'z'如何實例化? – Blundell
初始化?? float z = Float.parseFloat(String.valueOf(tv.getText())); – user1470125
那麼你是否在循環之前檢查給你什麼數字? 'Log.d(「TAG」,「Z is:」+ z);'p.s.如果'z'是用戶輸入,我只是把它作爲'int'' int z = Integer.parseInt(tv.getText()。toString());' – Blundell