5
I’m still a beginner, and I have the following question:
I’m inserting text from a EditText
in a array
, and I want to receive it in another. I am doing the following:
String[] pedidos = new String[11];
And then, by clicking on the "save" button, this happens:
public void onClick(View v) {
if(v.getId() == R.id.btnFinalizar){
pedidos[0] = edtPedido.getText().toString(); //insiro dados do EditText em uma array.
Intent intent = new Intent(mesa1.this, inicio.class);
intent.putExtra("pedidos1", pedidos[0]);
startActivity(intent);
}
}
And on the screen where I want to receive the data, I do this:
String[] pedidosFeitos = new String[11];
Intent intent = getIntent();
pedidosFeitos[0] = String.valueOf(intent.getStringArrayExtra("pedidos1"));
Note: I did not understand the: String.valueOf(intent.getStringArrayExtra
I researched to the maximum, and ended up trying what Android Studio suggested.
In the case of your implementation you are passing item by item of an array. Sending:
intent.putExtra("pedidos1", pedidos[0]);
and receivingpedidosFeitos[0] = String.valueOf(intent.getStringArrayExtra("pedidos1"));
. Along those linesString.valueOf(intent.getStringArrayExtra("pedidos1"));
will be converting a value (which should be an Array and not an Array item) to String.– akira-ito
A question: You want to send only one item at a time or all items at a time to another Activity?
– akira-ito
Man, sorry for the error, I ended up confusing array with vector, thanks for the correction. With your answer, and with the friend below, I managed to settle here, thank you very much.
– Nilzon Martins