上按一下按钮关闭自定义警告对话框 [英] Closing a custom alert dialog on button click

查看:101
本文介绍了上按一下按钮关闭自定义警告对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法关闭我的警告对话框。我使用的是布局充气,使对话,所以我不知道我怎么会去收东西,我用它做后。 code是如下:

I'm having trouble closing my alert dialog. I am using a layout inflator to make the dialog, so I'm not sure how I would go about closing the thing after I'm done with it. Code is below:

AlertDialog.Builder dialog = new AlertDialog.Builder(AddData.this);
        DialogInterface dia = new DialogInterface();

        //Create a custom layout for the dialog box
        LayoutInflater inflater = (LayoutInflater)AddData.this.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.add_rep_1_set, parent, false);

        TextView title = (TextView)layout.findViewById(R.id.rep_1_title);
        Button add_item = (Button)layout.findViewById(R.id.add_button);

        add_item.setOnClickListener(new OnClickListener()
        {
                @Override
                public void onClick(View v)
                {
                //Need this to close the alert dialog box
                }
        });

        title.setText(workout_items[position]);
        dialog.setView(layout);
        dialog.show();

我不能称之为完成,因为这将关闭从推出的警告对话框的列表视图,以及dialog.dismiss电话都没有提供给我。

I cant call finish, because that closes the listview that the alert dialog is launched from, and the dialog.dismiss calls are not available to me.

你觉得我应该做些什么来解决这个问题?

What do you think I should do to fix this?

推荐答案

像这样做,

add_item.setOnClickListener(new OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                        dialog.dismiss();
                }
            });

这篇关于上按一下按钮关闭自定义警告对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆