带有额外数据的初始化列表视图

时间:2013-07-27 01:17:33

标签: android android-intent android-listview

我开发了一个Android应用程序,其中包含通过从我的服务器加载项目初始化的列表视图。

我服务器中的数据包含三列id和内容及信息,我在listview中加载内容。

当我点击列表视图中的项目以在新活动中加载项目信息时,我需要。

当我尝试加载项目信息时,这里的问题出现在新活动中我需要项目ID。

所以我怎么能这样做?

这是初始化listview的代码

JSONArray jarray = new JSONArray(qresult);
        for ( int i =0; i<jarray.length();i++)
        {
            JSONObject json = jarray.getJSONObject(i);
            s = json.getString("Qcontent");
            q=json.getString("Qid");// how to send this id to the next activity
            listitems.add(s);
            adapter.notifyDataSetChanged();

        }

1 个答案:

答案 0 :(得分:0)

将它添加到你意图的附加内容中。

intent.putExtra("id", q);

然后开始活动。 在第二个活动的onCreate()中,添加

Bundle extras = getIntent().getExtras();
String q =  extras.getString("id"); //this is your id

另外,您可以考虑将notifyDataSetChanged()移到for循环之外。