2013-03-13 198 views
0

我已經在android.i中創建了一個自定義對話框,試圖用dismiss()來解除它,但是我的對話框仍然沒有被解僱,下面的代碼可以幫助我。如何關閉自定義對話框

void unsubPhoneNumberDialogBox(final ArrayList<String> unsubcribeList) 
{ 
    AlertDialog.Builder builder; 

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); 
    View layout = inflater.inflate(R.layout.customalert,null); 

    builder = new AlertDialog.Builder(SMSServiceListActivity.this); 
    builder.setView(layout); 
    alertDialog = builder.create(); 


    input = (EditText)layout.findViewById(R.id.txtPhoneNo); 
    btnVerify = (Button)layout.findViewById(R.id.btnSendSMS); 

    btnVerify.setOnClickListener(new OnClickListener() { 


     @Override 
     public void onClick(View v) { 

      InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
      imm.hideSoftInputFromWindow(input.getWindowToken(), 0); 

      alertDialog.dismiss(); 

     } 
    }); 

    alertDialog.show(); 
} 
+0

是對clickHandler被稱爲? – 2013-03-13 12:02:05

+0

您的'alertDialog'定義在哪裏?你可以做'builder.create()'&'builder.dismiss()'&'builder.show()'?還是我誤會了? – TronicZomB 2013-03-13 12:07:14

+0

@ Ahmed:是它被稱爲 – user578386 2013-03-13 12:14:38

回答

2

試試這個代碼,而不是:

.... 
Dialog alertDialog = new Dialog(SMSServiceListActivity.this); 
alertDialog.setContentView(R.layout.customalert); 
alertDialog.show(); 

input = (EditText)alertDialog.findViewById(R.id.txtPhoneNo); 
btnVerify = (Button)alertDialog.findViewById(R.id.btnSendSMS); 

btnVerify.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 
     InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
     imm.hideSoftInputFromWindow(input.getWindowToken(), 0); 
     alertDialog.dismiss(); 
    } 
}); 

.... 
+0

@ user578386它工作嗎? – KunalK 2013-03-13 12:21:45

+0

謝謝你的完全工作 – user578386 2013-03-13 12:24:24

+0

@ user578386總是WC :) – KunalK 2013-03-13 12:26:21