I have a ActivityA
that is the main, it contains a ListView
and a botão
, and I have a ActivityB
that contains two EditText
and a button.
When start app
starts in ActivityA
with empty list, pressing the button executes the following code
Intent it = new Intent(this, ActivityB.class);
startActivity(it);
Now I am in ActivityB
I 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 I'm in ActivityA
, inside onCreate
follows 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);
}
Ok, it works, but when I click the button again I go to ActivityB
, I type the values and click the button, I go to ActivityA
.