如何在适配器class中删除和设置对话框的视图?

How to remove and set the view of the dialog box in the adaptor class?

获取错误: 指定的 child 已经有一个 parent。您必须先在 child 的 parent 上调用 removeView()。

问题: 因为我反复调用警报生成器,所以首先我必须删除视图,然后需要重新设置视图。

问题:我不知道如何在适配器中删除和设置视图。

public class ActionAdaptor extends SectionRecyclerViewAdapter<SectionHeader, Action, SectionViewHolder, ActionChildGoal> {


    Context context;
    DbHelper dbHelper;
    HealthVitalsFunction interfaceAdapter;

    public ActionAdaptor(Context context, List<SectionHeader> sectionItemList) {
        super(context, sectionItemList);
        this.context = context;
        dbHelper = new DbHelper(context);
    }


    @Override
    public SectionViewHolder onCreateSectionViewHolder(ViewGroup sectionViewGroup, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.section, sectionViewGroup, false);
        return new SectionViewHolder(view);
    }

    @Override
    public  ActionChildGoal onCreateChildViewHolder(ViewGroup childViewGroup, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.action_list, childViewGroup, false);
        return new ActionChildGoal(view);
    }

    @Override
    public void onBindSectionViewHolder(SectionViewHolder sectionViewHolder, int sectionPosition, SectionHeader section) {
        sectionViewHolder.name.setText(section.getSectionText());
    }

    @Override
    public void onBindChildViewHolder(final ActionChildGoal holder, int sectionPosition, final int childPosition, final Action action) {



        //for more options

        //When nothing is there..
        if (action.getBenefits().length()==0 && action.getSideEffects().length() == 0 && action.getRemarks().length()==0){
            holder.moreOptions.setVisibility(View.GONE);
            holder.actionSubSection.setVisibility(View.GONE);
        }else {

            String msg=" ";

            if (action.getSideEffects().length()!=0)
                msg=msg.concat("<br /> <strong>Side Effects</strong> <br /> "+action.getSideEffects());

            holder.actionSubSection.setText(Html.fromHtml(msg));

            holder.actionSubSection.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    showDialogBox("More Information ",holder.actionSubSection);
                }
            });

        }


    public void showDialogBox(String title, View text)
    {


        final AlertDialog.Builder alert=new AlertDialog.Builder(new ContextThemeWrapper(context,R.style.AlertBoxTheme));
        alert.setView(new TextView(context));

        text.setPadding(3,0,3,0);
        alert.setView(text);
        alert.setTitle(title);


        alert.setPositiveButton("READ", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

                dialog.cancel();
            }
        });

        alert.show();
    }

}

您正在呼叫 alert.setView 2 次。就是这个问题。

这一行有问题:

     alert.setView(text); 

您正在尝试使用当前添加到 RecyclerView 中的视图设置警报对话框的视图,您需要创建新的视图或从 xml 扩展类似视图。