I have a dialog wherein a user can add EditText and also remove it. I have successfully added EditText programmatically but my code for removing it doesn't work. I'm following this tutorial but in my case setup is inside a dialog.
and also i want to get all the the texts on those EditTexts and store it inside an Array.
This is my code:
 public void showSurveyDialog(Context context) {
        ImageButton btnAddChoices, btnRemoveChoice;
        Dialog dialog = new Dialog(context);
        dialog.setContentView(R.layout.survey_content);
        dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        btnAddChoices = dialog.findViewById(R.id.btn_add_choices);
        LinearLayout choiceLayout = dialog.findViewById(R.id.choice_layout);
        btnAddChoices.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View rowView = dialog.getLayoutInflater().inflate(R.layout.choice_item, null);
                // Add the new row before the add field button.
                choiceLayout.addView(rowView, choiceLayout.getChildCount() - 1);
                ImageButton imageButton = dialog.findViewById(R.id.btn_choice_close);
                imageButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Log.e("asdass","ASDASd");
                        choiceLayout.removeView((View)v.getParent());
                    }
                });
            }
        });
        dialog.show();
    }
When pressing btnAddChoices a layout with EditText and Button(for removing) is automatically added to a linear layout. I'am trying to make the remove button to work but it doesn't remove the view.
 
    