1
I have a Listview
in my activity
main when I click a button, it adds data to my Listview
, so far everything is correct.
How do I show this listview
in another activity
? I show other data (EditText
) no problem, but listview
I couldn’t.
I tried to use it to send the data :
public void EnviarParaResultadoActivity(View view){
EditText resultadoID = (EditText) findViewById(R.id.resultadoID);
EditText nomesorteioID = (EditText) findViewById(R.id.nomesorteioID);
ListView listView1 = (ListView)findViewById(R.id.listView1);
Bundle parametro = new Bundle();
parametro.putString("resultadoID", resultadoID.getText().toString());
parametro.putString("nomesorteioID", nomesorteioID.getText().toString());
parametro.putString("listView1", listView1.getContext().toString());
Intent intent = new Intent(this, ResultadoActivity.class);
intent.putExtras(parametro);
startActivity(intent);
}
and to receive the data:
public void ReceberParametros() {
Intent intent = getIntent();
if(intent != null){
Bundle parametros = intent.getExtras();
if(parametros != null){
String resultadoID = parametros.getString("resultadoID");
String nomesorteioID = parametros.getString("nomesorteioID");
String listview1 = parametros.getString("listview1");
TextView ResultadoTV = (TextView)findViewById(R.id.resultadoID);
TextView NomesorteioTV = (TextView) findViewById(R.id.nomesorteioID);
ListView listviewLV = (ListView) findViewById(R.id.listView1);
ResultadoTV.setText(" "+resultadoID);
NomesorteioTV.setText(" "+nomesorteioID);
listviewLV.setFilterText(" "+listview1);
}
}
}
The data of TextView
They are displayed normally, but Listview
no. someone can help me?
How do I do it? I’m sorry, I’m a beginner and I didn’t get it right
– J.Silva
You know what it is
MVC
?– Costamilam
I know, model, view, controller
– J.Silva
Well, when you want to pass multiple data between activitys, instead of sending multiple String, int, Boolean..., you can set all the data in a model class and send that class (its instance), basically you create a new instance
Classe c - new Classe();
, arrow the values you want to pass with set and send withIntent.puExtra()
, and I believe the way you’re setting your listview is wrong– Costamilam