如何从列表视图中的一个paramater [英] How to get one paramater from list view
问题描述
我从JSON数据列表视图
i get data from json to list view
for (int i = 0; i < following.length(); i++) {
JSONObject c = following.getJSONObject(i);
// Storing each json item in variable
String nama = c.getString(KEY_NAMA);
String instansi = c.getString(KEY_INSTANSI);
String status = c.getString(KEY_STATUS);
id_user = c.getString(KEY_ID_USER);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(KEY_NAMA, nama);
map.put(KEY_INSTANSI, instansi);
map.put(KEY_STATUS, status);
map.put(KEY_ID_USER, id_user);
// adding HashList to ArrayList
followingList.add(map);
}
和行动,如果在列表视图点击
and action if listview on click
list = (ListView) activity.findViewById(R.id.listView1);
// Getting adapter by passing xml data ArrayList
adapter1 = new LazyAdapter(activity, followingList);
list.setAdapter(adapter1);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent profil = new Intent(activity.getApplicationContext(),
ProfilFollower.class);
profil.putExtra("id_user", id_user);
profil.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(profil);
// Closing dashboard screen
activity.finish();
}
});
我的问题如何从列表视图id_user拿到如果点击发送id_user paramater的意图
My question how to get id_user from list view to get if on click and send id_user paramater for intent
推荐答案
您可以使用以下
在您onItemClick(PARAMS)方法
In your onItemClick(params) methods
Intent profil = new Intent(ActivityName.this,
ProfilFollower.class);
profil.putExtra("id_user",
followingList.get(position).map.get(KEY_ID_USER).toString());
//map.get(KEY_ID_USER) where KEY_ID_USER is the key
另外声明
HashMap<String, String> map = new HashMap<String, String>();
的onCreate()在活动类中之前
before onCreate() inside the activity class
此外,使用此condiditon如果(followingList.size()> =位置)作为ρяσѕρєяK的他的回答提出。要知道为什么条件是必要的检查意见在ρяσѕρєяK公司的答案
Also use this condiditon if(followingList.size()>=position) as ρяσѕρєя K suggested in his answer. To know why the condition is necessary check the comment's in ρяσѕρєя K's answer
另外,请检查下面的链接和commonsware回答。使用Activity上下文到位getApplicationContext的()
Also check the link below and answer by commonsware. Use Activity context in place of getApplicationContext()
<一个href=\"http://stackoverflow.com/questions/7298731/when-to-call-activity-context-or-application-context\">When调用活动上下文或应用程序上下文?
这篇关于如何从列表视图中的一个paramater的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!