首先在孩子的父级上关闭alertDialog Android removeView() [英] Dismiss alertDialog Android removeView() on the child's parent first

查看:259
本文介绍了首先在孩子的父级上关闭alertDialog Android removeView()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想关闭/关闭警报对话框,但是当我单击按钮 valider 时,我遇到了这个错误:我什至不知道哪个视图给了我这个问题,即使没有删除视图的方法我的意见"布局"或" v "

I want to close/dismiss the alert Dialog but when I click in button valider I had this error : I don't know which views give me the problem, even there's no method remove View in my views "layout" or "v"

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:3562)
at android.view.ViewGroup.addView(ViewGroup.java:3415)
at android.view.ViewGroup.addView(ViewGroup.java:3391)
at com.android.internal.app.AlertController.setupView(AlertController.java:413)
at com.android.internal.app.AlertController.installContent(AlertController.java:241)
 at android.app.AlertDialog.onCreate(AlertDialog.java:337)
 at android.app.Dialog.dispatchOnCreate(Dialog.java:361)
 at android.app.Dialog.show(Dialog.java:262)
  at android.app.AlertDialog$Builder.show(AlertDialog.java:951)
  at com.surtymar.application.Fragments.FormContactFragment$6$1.onClick(FormContactFragment.java:503)

我不确定

 v.findViewById(R.id.btn_author).setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                LayoutInflater inflater = (LayoutInflater) LayoutInflater.from(getActivity());
                final View layout = inflater.inflate(R.layout.accomplice_layout_solution, null);
                layout.setBackgroundColor(colors.getBackMixColor(colors.getForeground_color(), 0.30f));
                ListView lv = (ListView) layout.findViewById(R.id.listForm);

                adapterAgent = new MyFormAgentAdapter((MainActivity) getActivity(), finalfieldsAgent, realm, colors, R.layout.form_row_item);

                lv.setAdapter(adapterAgent);
                final AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
                b.setView(layout);
                b.show();
                AllFilds.addAll(finalFields);

                layout.findViewById(R.id.btn_valide_form).setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {


                        v.findViewById(R.id.numberPinContainerAuthor).setVisibility(View.VISIBLE);
                        TextView textView = (TextView) v.findViewById(R.id.numberOfCatsAuthor);

                        int numbr = 0;
                        if(AllFilds.size() > 0)
                            numbr++;
                         textView.setText(""+numbr);

                        b.show().dismiss(); // the error is here


                    }
                });

            }
            return false;
        }
    });

推荐答案

更改此内容

final AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
            b.setView(layout);
            b.show();

final AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
    b.setView(layout);
    final AlertDialog alertDialog = b.show();

并更改此

b.show().dismiss();

if (alertDialog.isShowing())
        alertDialog.dismiss();

这篇关于首先在孩子的父级上关闭alertDialog Android removeView()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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