简体   繁体   中英

How to dismiss a custom dialog box

I have created a custom dialog box in android.i tried to dismiss it using dismiss().but still my dialog box not getting dismissed could u guys help me out below is the code.

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

try this code instead:

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

....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM