【发布时间】:2013-12-02 16:51:46
【问题描述】:
基本上,我希望使用值“test”和值“createdAt”填充 ListView。我已经想出了如何让任何一个出现在列表视图中,但不能同时出现。显然,我不明白这是如何在一个非常基本的层面上运作的。我不知道如何让两种不同的数据类型(字符串和日期)一起显示在同一个 ListView 元素中。我知道 SimpleAdapter 需要一个包含地图的列表,但是如果我只能在地图中存储一个键值对,我如何一次显示多个值?
public void done(List<ParseObject> results, ParseException e) {
if (e == null) {
ArrayList<HashMap<String, Date>> messages= new ArrayList<HashMap<String, Date>>();
for (ParseObject result : results) {
HashMap<String, Date> testMap = new HashMap<String,Date>();
HashMap<String, String> dateMap = new HashMap<String,String>();
testMap.put("test",(String)result.get("test"));
dateMap.put(createdAtKey,(Date)result.getCreatedAt());
messages.add(message);
//What do I do with the "test"values?
}
SimpleAdapter adapter = new SimpleAdapter(FeedActivity.this, messages,android.R.layout.simple_list_item_2, new String[] {testKey,createdAtKey}, new int[] {android.R.id.text1, android.R.id.text2 });
setListAdapter(adapter);
} else {
Log.e(TAG, "Exception caught!", e);
}
}
});
}
【问题讨论】:
-
你需要创建你自己的Adapter,继承BaseAdapter,然后你可以做任何你想做的事情。
标签: java android arraylist hashmap simpleadapter