Java tutorial
package com.tk.httpClientErp.inspectorfinalck; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ListView; import android.widget.SimpleAdapter; import com.tk.MyStore; import com.tk.httpClientErp.R; public class InspectorfinalckList extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String inspectorfinalckData = getIntent().getStringExtra("inspectorfinalckData"); List<HashMap<String, Object>> headManCheackDetail = jsonToListMap(inspectorfinalckData); List<HashMap<String, Object>> headManCheackfenzuList = classification(headManCheackDetail); MyStore.inspectorfinalckDetail = headManCheackDetail; MyStore.inspectorfinalckList = headManCheackfenzuList; String[] from = new String[] { "gd_no", "xm_name", "license", "bus_no" }; int[] to = new int[] { R.id.inspectorfinalck_list_orderno, R.id.inspectorfinalck_list_project, R.id.inspectorfinalck_list_License, R.id.inspectorfinalck_list_bus_no }; SimpleAdapter adapter = new SimpleAdapter(this, MyStore.inspectorfinalckList, R.layout.activity_inspectorfinalcklist, from, to); setListAdapter(adapter); } /** * JsionList<HashMap<String,Object>> * * @param strJsion * @return List<HashMap<String,Object>> * @throws JSONException */ private List<HashMap<String, Object>> jsonToListMap(String strJsion) { List<HashMap<String, Object>> busList = new ArrayList<HashMap<String, Object>>(); try { JSONObject jo = new JSONObject(strJsion); String jsArrayString = jo.getString("data"); JSONArray busArray = new JSONArray(jsArrayString); for (int i = 0; i < busArray.length(); i++) { JSONObject busObject = busArray.getJSONObject(i); HashMap<String, Object> busHashMap = new HashMap<String, Object>(); String gd_no = busObject.getString("gd_no"); // String gw_no = busObject.getString("gw_no"); String worker_name = busObject.getString("worker_name"); // String gs = busObject.getString("gs"); // String re_flag = busObject.getString("re_cnt"); // String workgroup_name = busObject.getString("workgroup_name"); // String headman_name = busObject.getString("headman_name"); // String start_time = busObject.getString("start_time"); // String finish_time = busObject.getString("finish_time"); // String check_time = busObject.getString("check_time"); // String wscheck_time = busObject.getString("wscheck_time"); // String xm_name = busObject.getString("xm_name"); // String license = busObject.getString("license"); // String bus_no = busObject.getString("bus_no"); busHashMap.put("bus_no", bus_no); busHashMap.put("xm_name", xm_name); busHashMap.put("license", license); busHashMap.put("gd_no", gd_no); busHashMap.put("gw_no", gw_no); busHashMap.put("worker_name", worker_name); busHashMap.put("gs", gs); busHashMap.put("re_flag", re_flag); busHashMap.put("workgroup_name", workgroup_name); busHashMap.put("headman_name", headman_name); busHashMap.put("start_time", start_time); busHashMap.put("finish_time", finish_time); busHashMap.put("check_time", check_time); busHashMap.put("wscheck_time", wscheck_time); busHashMap.put("mResult", false); // checkbox busList.add(busHashMap); } } catch (JSONException e) { e.printStackTrace(); } return busList; } /** * json * * @return */ private List<HashMap<String, Object>> classification(List<HashMap<String, Object>> jsontoList) { boolean initCompare = true; // true HashMap<String, Object> compareContainer = null; // List<HashMap<String, Object>> fenzuList = new ArrayList<HashMap<String, Object>>(); // if (jsontoList.size() == 0) return fenzuList; // HashSet<String> gd_no = new HashSet<String>(); for (HashMap<String, Object> bean : jsontoList) { gd_no.add(bean.get("gd_no").toString()); } // in_time for (String gdstr : gd_no) { compareContainer = new HashMap<String, Object>(); for (HashMap<String, Object> bean : jsontoList) { if (gdstr.equals(bean.get("gd_no").toString()) && initCompare) { compareContainer = bean; initCompare = false; } else if (gdstr.equals(bean.get("gd_no").toString())) { compareContainer = bean; } } fenzuList.add(compareContainer); initCompare = true; } return fenzuList; } @SuppressWarnings("unchecked") @Override public void onListItemClick(ListView l, View v, int position, long id) { HashMap<String, Object> wsHeadCheckBean = (HashMap<String, Object>) getListAdapter().getItem(position); Intent intent = new Intent(InspectorfinalckList.this, InspectorfinalckDetail.class); intent.putExtra("gd_no", wsHeadCheckBean.get("gd_no").toString()); startActivity(intent); } @Override public void onResume() { super.onResume(); ((SimpleAdapter) getListAdapter()).notifyDataSetChanged(); } }