-4

I have created a ListView that is populated with JSON data, and I have included OnItemClickListener to open a new Activity through Intent. What I'm trying to do is to make that new Activity generate data based on the item I have clicked in the ListView.

For example, if I clicked item from JSON field name JohnDoe in the ListView, I want to generate page with information from another JSON data file. And concrete example would be like the Google Play Store.

I click some app and it opens a page with populated info about that app.

Edit: I have tried that passing object link, and it doesnt work. I have getter and setter in a class, then I parse it in my main class.

Example here:

  JSONObject obj = response.getJSONObject(i);
                                    Movie movie = new Movie();
                                    movie.setTitle(obj.getString("title"));
Damian Kozlak
  • 7,065
  • 10
  • 45
  • 51
IDontEvenKnow
  • 122
  • 1
  • 1
  • 9
  • where is your approach ?? Too old question – IntelliJ Amiya Dec 08 '15 at 09:19
  • 1
    http://stackoverflow.com/questions/5082122/passing-jsonobject-into-another-activity Refer this link – Beena Dec 08 '15 at 09:21
  • I was trying that from the refer link, but it is not working. So thats why i placed this question for a detailed explanation. You need not down vote it if you haven't heard what i had to say more.. – IDontEvenKnow Dec 08 '15 at 09:29

2 Answers2

0

You can send an object as a parameter to another activity if the object implements Parcelable:

A typical implementation of Parcelable here

Then, to send like parameter, something like this:

Intent intent = new Intent(this, DetailMovieActivity.class);
intent.putExtra("key", movie);//Your object that implements Parcelable
startActivity(intent);

And in the other activity:

Bundle arguments = new Bundle();
Movie movie = getIntent().getParcelableExtra("key"));//Receive object

Good luck!

Jose Angel Maneiro
  • 1,226
  • 9
  • 20
0

If you do not like the Parcelable approach or do not know how to do it you can simply pass the JSONObject as a String like described here.

The only thing you have to worry about is retrieving the right JSONObject inside your OnItemClickListener.

Community
  • 1
  • 1
Jason Saruulo
  • 1,837
  • 4
  • 21
  • 21