Android在单击PositiveButton后不要关闭Ale

Android在单击PositiveButton后不要关闭Ale

本文介绍了Android在单击PositiveButton后不要关闭AlertDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在单击PositiveButton之后不关闭我的AlertDialog吗?

Can I just don't dismiss my AlertDialog after clicking PositiveButton?

我想保留对话框以在ArrayAdapter listWords上显示一些更新.

I would like to remain the dialog to show something update on my ArrayAdapter listWords.

这是我的代码.

AlertDialog.Builder sayWindows = new AlertDialog.Builder(MapActivity.this);

final EditText saySomething = new EditText(MapActivity.this);

sayWindows.setPositiveButton("ok",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    say = userName + " Says: "+saySomething.getText();
                    showPosition.setText(say);
                }
            });

sayWindows.setNegativeButton("cancel",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

sayWindows.setAdapter(listWords, null);
sayWindows.setView(saySomething);
sayWindows.create().show();

推荐答案

在查看@Little Child解决方案之后,我尝试做到这一点.让我们知道这是否适合您.

After looking at @Little Child solution, I try to make this. Let us know if this works for you.

    AlertDialog.Builder sayWindows = new AlertDialog.Builder(
            MapActivity.this);
    final EditText saySomething = new EditText(MapActivity.this);
    sayWindows.setPositiveButton("ok", null);
    sayWindows.setNegativeButton("cancel", null);
    sayWindows.setAdapter(listWords, null);
    sayWindows.setView(saySomething);

    final AlertDialog mAlertDialog = sayWindows.create();
    mAlertDialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {

            Button b = mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            b.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    // TODO Do something
                   say = userName + " Says: "+saySomething.getText();
                   showPosition.setText(say);
                }
            });
        }
    });
    mAlertDialog.show();

这篇关于Android在单击PositiveButton后不要关闭AlertDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:34