首页 > 解决方案 > copy existing linearLayout to a runtime alertDialog

问题描述

I have a maintenance application, where the operator does a checklist, and the previous steps are disabled, but I need to be able to go back to the previous step, and I would like to do this in an alertDialog

I created a setOnLongClickListener and I'm getting the View, and trying to add in alertDialog, but I get the exception that the layout has a parent (), when I remove View with, removeView (), it works, but I can't remove the View of princiapal activity

passo1.setOnLongClickListener(v -> {
        dialogBuilder = new AlertDialog.Builder(initManutencao.this);
        if (v.getParent() != null){
            ((ViewGroup) v.getParent()).removeView(v);
        }
        dialogBuilder.setView(v);
        alertDialog = dialogBuilder.create();
        alertDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
        alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        alertDialog.show();
        //disableItens.ShowItensScren(0, initManutencao.this);
        return false;
    });

In short, I need to copy a LinearLayout with all its contents to an alertDialog, without me removing it from the main activity when I press it.

Main Activity, should not be changed wanted but without removing LinearLayout from the main activity

标签: javaandroidandroid-alertdialog

解决方案


推荐阅读