Ich muss die Daten nach Entfernung von niedrigsten zum höchsten im ListView
sortiert haben. Ich bin mir nicht sicher, wie ich das machen soll? Jede Hilfe wird geschätzt. Dies ist mein Code, um die Daten nicht sicher zu bekommen, wie man sie richtig sortiert?Wie sortiere ich mit andriod HashMap <String, String> Abstandswert?
* Die Entfernungswerte wurden nicht aus den tatsächlichen Daten erhalten, aber die Entfernungswerte wurden aus dem Code selbst erhalten.
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);
}
}
}
Log
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)
Was 'slocationList' im obigen Code ist. – Bethan
Wird für Apps verwendet, die den Standort der Autowaschanlage angeben. Als ich jedoch versuchte, das Kabel zu codieren, verschwand der Bildschirm. Vielleicht ist es ein Problem mit Thread? –
Bitte senden Sie Ihren AsyncTask-Code. – Bethan