0

I'm trying to send an ArrayLists from MainActivity to SecondActivity. As a result, the ArrayLists should be displayed on ListView. I implemented a code, and instead of showing strings in ArrayLists, the value shows somewhat weird objects such as "com.example.projectid.Exampleitem@randomstrings". I want the objects to show strings that Arraylists have, instead of showing randome strings like this.

This is my MainActivity code to pass arraylists:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    openActivity2();
    return super.onOptionsItemSelected(item);
}

public void openActivity2(){
    Intent intent = new Intent(MainActivity.this, Activity2.class);
    intent.putExtra("mExamplelist",mExampleList);
    startActivity(intent);

}

My SecondActivity code is:

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_2);
    


    Bundle bundle=getIntent().getExtras();
    ArrayList<String>arrayList= bundle.getStringArrayList("mExamplelist");
    ArrayAdapter<String> items= new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,arrayList);
    ListView listView=findViewById(R.id.list_view);
    listView.setAdapter(items);
Dennis Kozevnikoff
  • 2,078
  • 3
  • 19
  • 29
BYcast
  • 1
  • 2
  • Exampleitem is the class of my Arraylists – BYcast Jan 07 '21 at 14:40
  • Does Exampleitem override the toString method? Are you sure the list of strings has the values you expect in MainActivity? It doesn't sound like the problem is passing from one activity to the other. – David Conrad Jan 07 '21 at 16:05
  • List of strings already exists in MainActivity and are displayed as well. I just want to see the list of strings in bigger recyclerview on SecondActivity. The problem occurs when I pass and receive the data. – BYcast Jan 08 '21 at 00:19
  • 1
    Please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) for this problem. – Stephen C Jan 08 '21 at 04:48

0 Answers0