How to store chains in a CharSequence obtained from an EdtiText?

0

Good evening my friends, I want to ask you a question that maybe for you is super simple, what I want to do is store chains in a CharSequence obtained from an EdtiText.

I explain when I click on a button, the value that contains the EditText is stored in the CharSequence the N times it is clicked, if in the EditText I write Apple then I click store apple , then type pear and store pear , etc.

to get something similar to this:

CharSequence[] frutas = {"mazana","pera", "..."};
    
asked by Luis Rene Mas Mas 26.08.2017 в 03:29
source

1 answer

0

I leave an example of what I have said, the idea is to add the elements in a list, and when you need the CharSequence convert the list in the array.

//esta lista almacenara tus string
List<String> lista = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    boton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //añade los string a la lista
            lista.add(editText.getText().toString());
        }
    });
    //esto convierte la lista a un CharSequence[]
    CharSequence[] charSequences = lista.toArray(new CharSequence[lista.size()]);
}
    
answered by 26.08.2017 / 07:00
source