0

I need to create as many Edittexts required when add button is clicked. And needs to retrieve datas in each EditTexts and store in a arrayList.

I have attached images below.

before clicking add button before clicking add button

after clicking new button, creates a new edit text after clicking new button, creates a new edit text

Rashiq
  • 650
  • 1
  • 9
  • 23
  • @ADM i have searched lots of posts regarding this. Could not find one. Thank you for the share. – Rashiq Jan 12 '18 at 10:59

1 Answers1

1

First you need to create two list variable:

List<EditText> list = new ArrayList<EditText>();
List<String> listText = new ArrayList<>();

Then, when you click the "new" button you need to add new EditText in your layout:

button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        EditText editText = new EditText(context);
        layout.addView(editText);
        list.add(editText);
    }
});

In another button click or whatever trigger you have you need to get text from EditText list:

for (EditText editText : list) {
    listText.add(editText.getText().toString());
}
Johny
  • 625
  • 2
  • 6
  • 26
Ergin Ersoy
  • 890
  • 8
  • 28