如何从适配器位置获取价值,我在下面有代码:
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 , link= http://192.168.103.121/xml/category.php?kat_id=13 , name=Category 13}
所以我的问题是,我想从名称中获取值并将其存储到变量字符串名称中,我只想在字符串名称中获得“Category 13”。因为我想将它传递给另一个活动。