0

I have a model and it implements the Parcelable interface, on my MainActivity I've like this

ArrayList<Model> modelList = new ArrayList<>();
for(int i = 1; i <= 5; i++)
modelList.add(new Model( "name "+ i , "number "+ i));

And I have a ListView of this modelList items.

What I'm trying to do is that when the user clicks on an item of the list I use Intent and put its extra like modelList.get(position)

I just want to put a specific object of the model, and not the whole model like intent.putParcelableArrayList("KEY", modelList)

Den
  • 283
  • 1
  • 9

2 Answers2

1

You might just need to do this

Intent().putExtra("name", yourModel)

putExtra has many overloads one of them is putExtra(name : String, value : Parcelable)

frankelot
  • 13,666
  • 16
  • 54
  • 89
1

You can pass it in following way.

intent.putExtra("KEY",modelList.get(position));

and get it in following way in another activity

Model model=getIntent().getParcelableExtra("KEY");
Riddhi Shah
  • 3,092
  • 5
  • 36
  • 56