1
I have a ActivityA
which is the main one, contains a ListView
and a botão
, and I have a ActivityB
containing two EditText
and a button.
When do I start app
begins in the ActivityA
with empty list, when pressing the button executes the following code
Intent it = new Intent(this, ActivityB.class);
startActivity(it);
Now I’m in the ActivityB
fill in the EditTex
and press the button that executes the following code
String texto = editTexto.getText().toString();
double numero = Double.parseDouble(editnumero.getText().toString());
Intent it = new Intent(this, ActivityA.class);
it.putExtra("texto", texto);
it.putExtra("numero", numero);
startActivity(it);
So am I in the ActivityA
, within the onCreate
follows the code
Intent it = getIntent();
texto = it.getStringExtra("texto");
numero = it.getDoubleExtra("numero", -1);
if(texto != null)
//List<Carro> carro = new ArrayLis<Carro>(); variável global
carro.add( new Desejo(texto,numero));
carroAdapter = new ArrayAdapter<Carro>(this, android.R.layout.simple_list_item_1,carro );
listaCarro.setAdapter(carroAdapter);
}
Okay, it works, but when I click the button again I go to ActivityB
, I type the values and I click the button, I go to ActivityA
. what had been added earlier was gone and the last data was triggered in the list.