【问题标题】:How to keep dialog box open on button click如何在按钮单击时保持对话框打开
【发布时间】:2013-06-18 05:04:57
【问题描述】:

如果再次按下按钮,我想保持对话框打开,但是当我按下它时,对话关闭。请帮助我如何保持开放对话

public class MainActivity extends Activity implements OnClickListener{

    Button b1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b1=(Button)findViewById(R.id.button1);
        b1.setOnClickListener(this);

    }

    @Override
    public void onClick(View arg0) {
         final Builder ad = new AlertDialog.Builder(this);

         ad.setCancelable(false);



        ad.setNegativeButton("Ok",  new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int arg1) { 
            }
        });     


        ad.setPositiveButton("Speak Again", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog,int arg1) {


            }});
        ad.show();

    }

【问题讨论】:

标签: android


【解决方案1】:

试试这个。

AlertDialog AD = new AlertDialog.Builder(YourActivity.this)
        .setTitle("Title")
        .setMessage("Message")
        .setNegativeButton("Ok", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

            }
        })
        .setPositiveButton("Speak Again", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog_main, int which) {
                // TODO Auto-generated method stub

            }
        }).show();

【讨论】:

    【解决方案2】:

    好吧,你正在使用对话框。这意味着一旦按下按钮它就会关闭。 您可以在获得“再次发言”按钮时重新打开对话框,或者您可以创建自己的 Jform,以便在按下“再次发言”按钮时不会关闭。

    我建议您创建自己的表单

    【讨论】:

    • 如何制作自己的Jform?尝试在谷歌上寻找简单的例子。他们只有数百万
    猜你喜欢
    • 2014-03-08
    • 2011-06-18
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多