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.
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.
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());
}