com.tk.httpClientErp.initialcheck.InitialcheckListActivity.java Source code

Java tutorial

Introduction

Here is the source code for com.tk.httpClientErp.initialcheck.InitialcheckListActivity.java

Source

package com.tk.httpClientErp.initialcheck;

import java.util.ArrayList;
import java.util.HashMap;
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 InitialcheckListActivity extends ListActivity {

    private boolean mResult = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String mFirstInspectionData = getIntent().getStringExtra("firstInspectionData");
        List<HashMap<String, Object>> firstInspectionData = jsonToListMap(mFirstInspectionData);
        MyStore.firstInspectionList = firstInspectionData;
        String[] from = new String[] { "id", "license", "lineName", "busTypeName", "spaceName", "xmName",
                "bus_no" };// ,"line_name","bus_type_name","space_name","xm_name"
        int[] to = new int[] { R.id.fi_id, R.id.fi_license, R.id.fi_lineName, R.id.fi_bus_type_name,
                R.id.fi_space_name, R.id.fi_xm_name, R.id.fi_bus_no };
        SimpleAdapter adapter = new SimpleAdapter(this, MyStore.firstInspectionList,
                R.layout.activity_firstinspectionlist, 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);
            JSONArray busArray = new JSONArray(jo.getString("data"));
            for (int i = 0; i < busArray.length(); i++) {
                JSONObject busObject = busArray.getJSONObject(i);
                HashMap<String, Object> busHashMap = new HashMap<String, Object>();
                String id = busObject.getString("id"); // 
                String busTypeName = busObject.getString("bus_type_name"); // 
                String licenseString = busObject.getString("license"); // 
                String spaceName = busObject.getString("space_name"); // 
                String xmName = busObject.getString("xm_name"); // 
                String lineName = busObject.getString("line_name"); // 
                String bus_no = busObject.getString("bus_no");//

                busHashMap.put("id", id);
                busHashMap.put("busTypeName", busTypeName);
                busHashMap.put("license", licenseString);
                busHashMap.put("spaceName", spaceName);
                busHashMap.put("xmName", xmName);
                busHashMap.put("lineName", lineName);
                busHashMap.put("bus_no", bus_no);

                busHashMap.put("kqlqq", mResult);
                busHashMap.put("qblqq", mResult);
                busHashMap.put("jjykg", mResult);
                busHashMap.put("xyd", mResult);
                busHashMap.put("sxg", mResult);
                busHashMap.put("yxg", mResult);
                busHashMap.put("byclg", mResult);
                busHashMap.put("dcj", mResult);
                busHashMap.put("zyb", mResult);
                busHashMap.put("sjhl", mResult);
                busHashMap.put("sjhdb", mResult);
                busHashMap.put("drz", mResult);
                busHashMap.put("srz", mResult);
                busHashMap.put("qdfbl", mResult);
                busHashMap.put("hdfbl", mResult);
                busHashMap.put("mfs", mResult);
                busHashMap.put("cxfs", mResult);
                busHashMap.put("tccg", mResult);
                busHashMap.put("sxz", mResult);
                busHashMap.put("ygqjp", mResult);
                busHashMap.put("dlb", mResult);
                busHashMap.put("lban", mResult);
                busHashMap.put("dfs", mResult);
                busHashMap.put("bzq", mResult);
                busHashMap.put("dd", mResult);
                busHashMap.put("xdq", mResult);
                busHashMap.put("xdh", mResult);
                busHashMap.put("fwd", mResult);
                busHashMap.put("zxdq", mResult);
                busHashMap.put("zxdh", mResult);
                busHashMap.put("zdd", mResult);
                busHashMap.put("dcd", mResult);
                busHashMap.put("pzd", mResult);
                busHashMap.put("ddeng", mResult);
                busHashMap.put("xd", mResult);
                busHashMap.put("jyb", mResult);
                busHashMap.put("dlbiao", mResult);
                busHashMap.put("qyb", mResult);
                busHashMap.put("swb", mResult);
                busHashMap.put("qybiao", mResult);
                busHashMap.put("lcb", mResult);
                busHashMap.put("mhq", mResult);
                busHashMap.put("cxbl", mResult);
                busHashMap.put("pxan", mResult);
                busHashMap.put("dqkg", mResult);
                busHashMap.put("dzxsp", mResult);
                busHashMap.put("tbx", mResult);
                busList.add(busHashMap);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return busList;
    }

    @SuppressWarnings("unchecked")
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        HashMap<String, Object> busBean = (HashMap<String, Object>) getListAdapter().getItem(position);
        Intent intent = new Intent(InitialcheckListActivity.this, InitialcheckDetailActivity.class);
        intent.putExtra("id", busBean.get("id").toString());
        startActivity(intent);
    }

    @Override
    public void onResume() {
        super.onResume();
        ((SimpleAdapter) getListAdapter()).notifyDataSetChanged();
    }
}