Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
946 views
in Technique[技术] by (71.8m points)

android - How to pass JSON data from ListView to new activity

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"));
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...