0

我在android中创建了一个自定义对话框。我尝试使用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();
}
4

1 回答 1

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

....
于 2013-03-13T12:02:16.833 回答