如何从ListView的新活动传递JSON数据 [英] How to pass JSON data from ListView to new activity
问题描述
我创建了一个填充了
JSON
的数据,我已经包含的ListView OnItemClickListener
通过活动
>意图。我想要做的是使新的活动
生成基于我已经点击了的ListView
。
例如,如果我点击项目从 JSON
字段名称 JOHNDOE
在的ListView
,我想从另一个 JSON
数据文件的信息来生成页面。而具体的例子是像谷歌Play商店。
我点击了一些应用程序,它会打开一个页面,关于该应用的填充信息。
编辑:我已尝试通过对象链接,它不工作。我有getter和setter一类的话,我分析它在我的主类。
例如,在这里:
的JSONObject的obj = response.getJSONObject(I)
电影电影=新电影();
movie.setTitle(obj.getString(标题));
您可以将对象作为参数传递给另一个活动,如果对象实现的 Parcelable
然后,送样的参数,这样的事情:
意向意图=新意图(这一点,DetailMovieActivity.class);
intent.putExtra(钥匙,电影); //你的目标实现Parcelable
startActivity(意向);
而在其他活动:
捆绑参数=新包();
电影电影= getIntent()getParcelableExtra(密钥)); //接收对象
祝你好运!
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"));
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!
这篇关于如何从ListView的新活动传递JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!