繁体   English   中英

如何关闭此AlertDialog?

[英]How can I dissmiss this AlertDialog?

我必须使用搜索栏将产品添加到购物车中,并将数量添加到警报对话框中。 我的问题是隐藏此警报对话框,然后返回我的原始视图。

有人可以帮我解决这个问题吗?

public void onClick(View v) {
             AlertDialog.Builder builder = new AlertDialog.Builder(
                    ProductDetail.this);
            LayoutInflater inflater = ProductDetail.this
                    .getLayoutInflater();
            View v1 = inflater.inflate(R.layout.android_dialog, null);
            builder.setView(v1).setIcon(R.drawable.basket)
                    .setTitle("Add " + Product_name + " to your list");

            SeekBar sbBetVal = (SeekBar) v1.findViewById(R.id.seekBar2);

            tvBetVal = (TextView) v1.findViewById(R.id.total_price);
            Button b1 =(Button)v1.findViewById(R.id.button1);
            Button b2=(Button)v1.findViewById(R.id.button2);
            b2.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {


                }
            });
            b1.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Log.e("Prixtotal",""+v22);
                    new CreateNewProduct().execute();

                }
            });

实际上, AlertDialog.Builder类没有任何stop()dismiss()方法。

您必须使用AlertDialog.Builder类的.create()方法创建AlertDialog对象。

然后在AlertDialog对象上调用.dismiss() .Stop().dismiss()

你必须写

final AlertDialog alertDialog = builder.create();

然后

采用

alertDialog.show();

显示对话框并消除警报使用

alertDialog.dismiss();

我的问题是隐藏此警报对话框并返回到我的原始视图。

=>您只需要关闭该对话框。 它将自动返回到您的原始视图,该视图可能是您的产品列表。

您必须创建一个AlertDialog对象,您可以随时随地调用dismiss()方法来关闭对话框。

AlertDialog dialog = new AlertDialog.Builder(this).create(); 
dialog .dismiss();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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