【发布时间】:2013-01-18 06:08:45
【问题描述】:
如何从适配器位置获取价值,我在下面有代码:
CategoriesXmlParser categoryXmlParser = new CategoriesXmlParser();
List<HashMap<String, Object>> categories = null;
try {
categories = categoryXmlParser.parse(reader);
} catch (Exception e) {
Log.d("Exception", e.toString());
}
String[] from = { "name", "image" };
int[] to = { R.id.nama_category, R.id.logo_category };
final SimpleAdapter adapter = new SimpleAdapter(getBaseContext(),
categories, R.layout.per_item_category, from, to);
mListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Object obj = mListView.getAdapter().getItem(position);
String value = obj.toString();
Log.d("MyLog", "Value is: "+value);
String name = // how code to get name value.
}
});
如果我在 MyLog 中的 logcat 上查看它,我会得到:
值为:{position=12, image_path=http://192.168.103.121/xml/icon.png, 链接=http://192.168.103.121/xml/category.php?kat_id=13,名称=类别 13}
所以我的问题是,我想从名称中获取值并将其存储到变量字符串名称中,我只想在字符串名称中获得“Category 13”。因为我想将它传递给另一个活动。
【问题讨论】:
-
嗯,你用什么类型的对象填充你的适配器?您可以简单地将
getItem()的结果转换为该结果,然后使用您实现的任何访问器来检索name字段的值。
标签: android listview listview-adapter