2013-11-20 83 views
0

在我的代碼中,我希望立即關閉提醒對話框並啓動活動,當我選擇if- elseIf語句中提到的選項時。我不想確定並取消按鈕。我的代碼工作正常(語句內部的語句工作,但仍然存在快速對話)。感謝您的幫助android中的提醒對話框

final AlertDialog.Builder builder = 
    new AlertDialog.Builder(arg0.getContext()); 
builder.setTitle("Favourities Management"); 
// TODO Auto-generated method stub 
int selected = 0; 

builder.setSingleChoiceItems(values, selected, new DialogInterface.OnClickListener() { 

    @ 
    Override 
    public void onClick(DialogInterface dialog, int which) { 
     if (values[which] == "Select Benificiary") { 
      Intent registerUser = new Intent(FinalUtilityBillPayment.this, ListViewBeneficiaryBillPayment.class); 
      FinalUtilityBillPayment.this.startActivity(registerUser); 
      startActivityForResult(registerUser, 1); 
     } else if (values[which] == "Add Benificiary") { 
      try { 
       mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE, null); 
       mydb.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE + " (ID INTEGER PRIMARY KEY, ReferenceNo TEXT, Mobile Text);"); 

       mydb.close(); 
      } catch (Exception e) { 
       Toast.makeText(getApplicationContext(), "Error in creating table", Toast.LENGTH_LONG).show(); 
      } 
      try { 
       mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE, null); 
       mydb.execSQL("INSERT INTO " + TABLE + "(ReferenceNo, Mobile) VALUES('" + ref.getText().toString() + "','" + mob.getText().toString() + "')"); 
       mydb.close(); 
      } catch (Exception e) { 
       Toast.makeText(getApplicationContext(), "Error in inserting into table", Toast.LENGTH_LONG).show(); 
      } 
     } else if (values[which] == "Delete Benificiary") { 

      Intent registerUser = new Intent(FinalUtilityBillPayment.this, ListViewDeleteBeneficiaryBillPayment.class); 
      //startActivityForResult(registerUser, 1); 
      FinalUtilityBillPayment.this.startActivity(registerUser); 




     } 

    } 
}); 
AlertDialog alert = builder.create(); 
alert.show(); 


} 

}); 
+0

如果你不想確定並取消按鈕,而不是你爲什麼使用警報對話框? –

+0

解僱不工作...我想彈出選項選擇點擊..是任何其他選項? – user2768215

+0

http://stackoverflow.com/a/4805906/1318946 –

回答

1

我消化不良

final AlertDialog.Builder builder = new AlertDialog.Builder(arg0.getContext()); 
builder.setTitle("Favourities Management");  
// TODO Auto-generated method stub 
int selected = 0; 
builder.setSingleChoiceItems(values, 
          selected, 
          new DialogInterface.OnClickListener() { 

            @Override 
            public void onClick(DialogInterface dialog, int which) { 
             if(values[which]=="Select Benificiary"){ 
              selectBenificiary(); 

              //see more about "dialog.dismiss()" in http://developer.android.com/reference/android/app/Dialog.html#dismiss() 
              dialog.dismiss();            
             } else if (values[which]=="Add Benificiary"){ 
              addBenificiary(); 

              //see more about "dialog.dismiss()" in http://developer.android.com/reference/android/app/Dialog.html#dismiss() 
              dialog.dismiss(); 
             } else if (values[which]=="Delete Benificiary"){ 
              deleteBenificiary(); 

              //see more about "dialog.dismiss()" in http://developer.android.com/reference/android/app/Dialog.html#dismiss() 
              dialog.dismiss(); 
             } 

            } 
          }); 
AlertDialog alert = builder.create(); 
alert.show(); 

//Add parameter case necessary 
public void selectBenificiary(){ 
    Intent registerUser = new Intent(FinalUtilityBillPayment.this,ListViewBeneficiaryBillPayment.class); 
    // FinalUtilityBillPayment.this.startActivity(registerUser); 
    startActivityForResult(registerUser, 1); 
} 

//Add parameter case necessary 
public void addBenificiary(){ 
    try{ 
     mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null); 
     mydb.execSQL("CREATE TABLE IF NOT EXISTS "+ TABLE +" (ID INTEGER PRIMARY KEY, ReferenceNo TEXT, Mobile Text);"); 

     mydb.close(); 
    }catch(Exception e){ 
     Toast.makeText(getApplicationContext(), "Error in creating table", Toast.LENGTH_LONG).show(); 
    } 

    try{ 
     mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null); 
     mydb.execSQL("INSERT INTO " + TABLE + "(ReferenceNo, Mobile) VALUES('"+ref.getText().toString() +"','"+ mob.getText().toString() +"')"); 
     mydb.close(); 
    }catch(Exception e){ 
     Toast.makeText(getApplicationContext(), "Error in inserting into table", Toast.LENGTH_LONG).show(); 
    } 
} 

//Add parameter case necessary 
public void deleteBenificiary(){ 
    Intent registerUser = new Intent(FinalUtilityBillPayment.this, ListViewDeleteBeneficiaryBillPayment.class); 
    //startActivityForResult(registerUser, 1); 
    FinalUtilityBillPayment.this.startActivity(registerUser); 
} 
+0

你是awsum..thnx – user2768215

0

您必須關閉警報對話框。試試這個:

Dialogue.dismiss(); 
0

嘗試......在onClick()你可以看到DialogInterface dialog該對話框名稱。

使用本dialog.cancel();調用其他活動

dialog.cancel(); 

    Intent registerUser = new Intent(FinalUtilityBillPayment.this,ListViewBeneficiaryBillPayment.class); 
    //FinalUtilityBillPayment.this.startActivity(registerUser);  
    startActivityForResult(registerUser, 1); 
0

調用.dismiss()用於closiong它之前,還可以使用簡單的對話框,獲得設置自定義佈局的可能性,因爲它

Dialog alert = new Dialog(context); 
alert.setContentView(layoutResID); 
相關問題