我用谷歌搜索了它,并尝试了一些例子,但我总是卡住。
这是错误消息,当我尝试使用时Collections.sort
:
sort(List<T>)
类型的泛型方法Collections
不适用于参数 (ArrayList<HashMap<String,String>>
)。推断的类型HashMap<String,String>
不是有界参数的有效替代品<T extends Comparable<? super T>>
。
我的代码与此类似。
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
//Get the data (see above)
JSONObject json = JSONfunctions.getJSONfromURL("http://xxxxxxxxxxxxxxxxxxxxxx");
try {
//Get the element that holds the earthquakes ( JSONArray )
JSONArray earthquakes = json.getJSONArray("earthquakes");
//Loop the Array
for (int i = 0; i < earthquakes.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = earthquakes.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("name", "Earthquake name:" + e.getString("eqid"));
map.put("magnitude", "Magnitude: " + e.getString("magnitude"));
mylist.add(map);
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.main,
new String[]{"name", "magnitude"},
new int[]{R.id.item_title, R.id.item_subtitle});
setListAdapter(adapter);