У меня есть диалог, в котором пользователь может добавить EditText, а также удалить его.Я успешно добавил EditText программно, но мой код для его удаления не работает.Я следую этому учебнику, но в моем случае настройка находится внутри диалога.
, а также я хочу получить все тексты этих EditTexts и сохранить их в массиве.
Это мой код:
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();
}
При нажатии btnAddChoices макет с EditText и Button (для удаления) автоматически добавляется в линейный макет.Я пытаюсь заставить кнопку удаления работать, но она не удаляет вид.