如何关闭自定义对话框

时间:2013-03-13 11:49:36

标签: android

我在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();
}

1 个答案:

答案 0 :(得分: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();
    }
});

....