Android上的垂直进度条

时间:2017-03-23 08:37:46

标签: android android-layout listview adapter

我想在列表视图上实现进度条,以获取从Mysql服务器获取的数据这里是我的代码欢迎任何新的建议,例如更改您的布局或任何将使实现变得容易的新手

public class teststatusActivity extends BaseActivity {

String myJSON = "" ;
private static final String TAG_RESULTS = "result";
private static final String TAG_TICKET = "ticket_id";
private static final String TAG_Status = "ticket_status";
private static final String TAG_Status1 = "ticket_status1";
private static final String TAG_Status2 = "ticket_status2";
private static final String TAG_Status3 = "ticket_status3";



private static final String TAG_I = "";

public static final String DATA_URL = "http://103.3.62.23/complain_dashboard/api/getTicketStatus.php?ticket_id=";

public String ticketID;




JSONArray peoples = null;


ListView list;


ArrayList<HashMap<String, String>> usersList;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_teststatus);
    list = (ListView) findViewById(R.id.listView);



    usersList = new ArrayList<HashMap<String, String>>();
    getData();


}

protected void showList() {
    try {
        JSONObject jsonObj = new JSONObject(myJSON);
        JSONObject pe = jsonObj.getJSONObject(TAG_RESULTS);


        String id = pe.getString("ticket_id");
        String status = pe.getString("ticket_status");
        String stat = null;
        String stat1 = null;
        String stat2 = null;
        String stat3 = null;



        if (pe.get("ticket_status").equals("0")) {
            stat = "Feedback Sent To Team";
        }
         if (pe.get("ticket_status").equals("1")) {
            stat1 = "Technical Team is Working on it";
        }

         if (pe.get("ticket_status").equals("2")) {
            stat2 = "Your Report is About To Resolve";
        }
        if (pe.get("ticket_status").equals("3")) {
            stat3 = "Resolved";
        }


        HashMap<String, String> users = new HashMap<String, String>();

        users.put( TAG_TICKET , id  );
        users.put(TAG_Status,  stat );
       users.put(TAG_Status1,  stat1 );
       users.put(TAG_Status2,  stat2);
       users.put(TAG_Status3,  stat3);



        usersList.add(users);


        ListAdapter adapter = new SimpleAdapter(
                teststatusActivity.this, usersList, R.layout.list_item,
                new String[]{TAG_TICKET, TAG_Status,TAG_Status1, TAG_Status2, TAG_Status3 },
                new int[]{R.id.feed, R.id.feedS, R.id.feedwork, R.id.abouttoresolve, R.id.resolved}
        );

        list.setAdapter(adapter);

    } catch (JSONException e) {
        e.printStackTrace();
    }

}

public void getData() {



   class GetDataJSON extends AsyncTask<String, Void, String> {
       SharedPreferences sharedPref = getSharedPreferences("tcktid", Context.MODE_WORLD_READABLE);
       final String ticket =sharedPref.getString("tid", null);

        @Override
        protected String doInBackground(String... params) {
            DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());


            HttpPost httppost = new HttpPost(DATA_URL + ticket);

            // Depends on your web service
            httppost.setHeader("Content-type", "application/json");


            InputStream inputStream = null;
            String result = null;
            try {
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                inputStream = entity.getContent();
                // json is UTF-8 by default
                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
                StringBuilder sb = new StringBuilder();

                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                result = sb.toString();
            } catch (Exception e) {
            } finally {
                try {
                    if (inputStream != null) inputStream.close();
                } catch (Exception squish) {
                }
            }
            return result;
        }


        @Override
        protected void onPostExecute(String result) {
            myJSON = result;
            showList();
        }
    }

    GetDataJSON g = new GetDataJSON();
            g.execute();


        }


    } ;

0 个答案:

没有答案