我需要按ListView
中从最低到最高的距离排序数据。我不知道如何去做这件事?任何帮助赞赏。这是我的代码来抓取数据不知道如何让它正确排序?如何使用andriod进行排序HashMap <String,String>距离值?
*没有从实际数据获得的距离值,但是从代码本身获得的距离值。
public void showList(){
try {
JSONObject jsonObj = new JSONObject(sJSON); //String sJSON
jsonArray = jsonObj.getJSONArray(TAG_RESULTS); //JSONArray jsonArray = null;
for (int i = 0; i < jsonArray.length(); i++) {
c = jsonArray.getJSONObject(i); //JSONObject c;
//String id = c.getString(TAG_ID);
name = c.getString(TAG_NAME);
address = c.getString(TAG_ADD);
String phone = c.getString(TAG_PHONE);
String dlatitude = c.getString(TAG_LAT);
String dlongitude = c.getString(TAG_LONG);
lat = Double.parseDouble(dlatitude);
longi = Double.parseDouble(dlongitude);
Location curlocation = new Location("curpoint");
curlocation.setLatitude(latitude);
curlocation.setLongitude(longitude);
Location datalocation = new Location("datapoint");
datalocation.setLatitude(lat);
datalocation.setLongitude(longi);
distance = curlocation.distanceTo(datalocation);
meter = Double.toString(distance);
HashMap<String, String> location = new HashMap<String,String();
//location.put(TAG_ID,id);
location.put(TAG_NAME, name);
location.put(TAG_ADD, address);
location.put(TAG_PHONE, phone);
location.put(TAG_LAT, dlatitude);
location.put(TAG_LONG, dlongitude);
location.put(TAG_DIS, "DISTANCE" + meter + "m");
slocationList.add(location);
ListAdapter adapter = new SimpleAdapter(CurrentLocationActivity.this, slocationList, R.layout.list_item,new String[]{TAG_NAME, TAG_ADD, TAG_PHONE, TAG_LAT,TAG_LONG,TAG_DIS},new int[]{R.id.name, R.id.address, R.id.phone,R.id.latitude,R.id.longitude, R.id.distance});
list.setAdapter(adapter);
}
}
}
登录
at android.os.AsyncTask.finish(AsyncTask.java:679)
at android.os.AsyncTask.access$500(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:696)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5639)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689)
什么是'slocationList'在上面的代码。 – Bethan
用于指示洗车位置的应用程序。但是,当我试图对电源线进行编码时,屏幕消失了。也许,这是线程问题吗? –
请发布您的AsyncTask代码。 – Bethan