0

如何从此 Hashmap 中获取日期。
如何获得可变目的?
我想要这些数据并将其转换为日期格式。

ArrayList<Map<String, String>> list = buildData();
    String[] from = { "name", "purpose" };
    int[] to = { android.R.id.text1, android.R.id.text2 };

    SimpleAdapter adapter = new SimpleAdapter(this, list,
            android.R.layout.simple_list_item_2, from, to);
    setListAdapter(adapter);
}

private ArrayList<Map<String, String>> buildData() {
    ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
    list.add(putData("A", "20.7.2013"));
    list.add(putData("B", "21.7.2013"));
    list.add(putData("C", "22.7.2013"));
    return list;
}

public HashMap<String, String> putData(String name, String purpose) {
    HashMap<String, String> item = new HashMap<String, String>();
    item.put("name", name);
    item.put("purpose", purpose);
    return item;
}
4

1 回答 1

0

您需要使用 DateFormat 将字符串转换为日期。可能是这样的东西可以帮助你

private void getDate(){
     SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy");
    for( Map<String, String> m : list){
        String dateStr = m.get("A");
        Date formated = format.parse(dateStr);// This will parse the String i.e. purpose and return the date obj

    }
}

编辑使用

public HashMap<String, String> putData(String name, String purpose) {
HashMap<String, String> item = new HashMap<String, String>();
item.put(name, purpose);
return item;

}

于 2013-07-17T03:59:52.990 回答