Save several variables in an Edittext

Asked

Viewed 62 times

-1

Hello, my problem is how to save different strings that are written in an Editview.

I can save a variable every time a button is pressed. But I don’t know how to save another string in another variable, someone can help me?

(Another question would be how to create variables in an automatic way without declaring before)

  • See the class Arraylist

1 answer

1

To store multiple variables, you need a structure to add multiple variables.

If you know how many entries you will have you can use an Array:

String[] valores = new String[5] // 5 = o número de "gavetas" que seu Array terá

This way you can access the content by doing valores[índice]

When you don’t know how many entries you will have, you can use a Object List.

List<String> minhaLista = new ArrayList<>();

This way, when you need to store a variable, use minhaLista.add("Minha String"); and to recover the value use minhaLista.get(índice)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.