Extract data from an EditText and add them to object

0

I have the following code:

      ArrayList<Lista_entrada> llibres = new ArrayList<Lista_entrada>();

    // Afegim uns llibres d'exemple.
    llibres.add(new Lista_entrada( "BUHO", "Búho es el nombre común d."));
    llibres.add(new Lista_entrada( "COLIBRÍ", "Los troquilinos"));

The doubt that I have is right now I introduce it directly. But I would like to be able to extract the data of two EditText .

I have the problem because:

llibres.add(new Lista_entrada( String, String ); (Wait 2 strings )

Can you give me an example of how to fill it with the content of 2 EditText ?

    
asked by Montse Mkd 17.10.2018 в 16:44
source

2 answers

1

I do not understand your question very well.

but I imagine you want to get the values of two EditText .. and add them to the list.

I guess you should just do this.

define the EditText

EditText EditText1= findViewById(R.id.EditText1);
EditText EditText2 = findViewById(R.id.EditText2);

you get the values of each EditText

String text1 = EditText1.getText();
String text2 = EditText2.getText();

fill the list

llibres.add(new Lista_entrada( text1 , text2 ); 
    
answered by 17.10.2018 / 16:51
source
0

llibres is a list of objects Lista_entrada

 ArrayList<Lista_entrada> llibres = new ArrayList<Lista_entrada>();

If you want to insert values of two EditText towards each object Lista_entrada , get the texts of the TextView (obviously you should get the references of EditText in your layout by findViewById(R.id.<id EditText>) )

   //Obtiene datos de los EditText.
   String texto1 = EditText1.getText();
   String texto2 = EditText2.getText();
   //Crea objeto con valores de los EditText.    
   Lista_entrada elementoLista = new Lista_entrada( texto1 , texto2 );
   //Agrega elemento a lista. 
   llibres.add(elementoLista);

or simply add the values directly

   //Crea objeto con valores de los EditText.    
   Lista_entrada elementoLista = new Lista_entrada( EditText1.getText(), EditText2.getText());
   //Agrega elemento a lista. 
   llibres.add(elementoLista);
    
answered by 17.10.2018 в 17:18