Listview in another Activity

1

I have a Listview in my activity main when I click on a button, it adds data in my Listview , so everything is correct.

How do I show this listview to another activity ? I show other data ( EditText ) without problems, but listview I could not.

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);

            }
        }
    }

TextView data is displayed normally, but Listview is not displayed. Can anyone help me?

    
asked by anonymous 16.11.2017 / 17:15

1 answer

1

To send the data, it is necessary to set the values in a class and send them with putExtra() :

Intent it = new Intent(this, ResultadoActivity.class);
it.putExtra("objeto", classModel);
startActivity(it);

And to paste:

ClassModel cm = (ClassModel) getIntent().getSerializableExtra("objeto");

And ClassModel must have implements Serializable :

public class ClassModel implements Serializable {
    //Código...
}

To set the data in ListView :

ArrayList<ClassModel> array = cm.getArray(); //cm.getArray deve conter o array de dados que vão ser setados no listView
ArrayAdapter<ClassModel> adapter = new ArrayAdapter<>(SegundaActivity.this, android.R.layout.simple_list_item_1, array);
listview1.setAdapter(adapter);
    
16.11.2017 / 17:23