1

I want show server json responce in listview.i get all value in hashmap i am confused about how to set that data in custom listview.please help me and show me the code

class viewticket extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pdialog = new ProgressDialog(UserLogedIn.this);
        pdialog.setMessage("Loading....");
        pdialog.setIndeterminate(false);
        pdialog.setCancelable(false);
        pdialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {
        List<NameValuePair> param = new ArrayList<NameValuePair>();
        param.add(new BasicNameValuePair("userid", u_id));
        JSONObject jsonArray = jpar.makeHttpRequest(URLMyTicket, "POST", param);
        ServiceHandler sh = new ServiceHandler();

        // Making a request to url and getting response
        String jsonStr = sh.makeServiceCall(URLMyTicket, ServiceHandler.POST, param);
        Log.d("Response: ", "> " + jsonStr);
        if (jsonStr != null) {
            try {

               contacts = new JSONArray(jsonStr);
                int a=contacts.length();
                Log.v(TAG,""+a);
                for (int i = 0; i < contacts.length(); i++) {
                    JSONObject c = contacts.getJSONObject(i);

                    String id = c.getString(TAG_ID);
                    String name = c.getString(TAG_PROB);
                    String email = c.getString(TAG_DESC);
                    HashMap<String, String> contact = new HashMap<String, String>();
                    contact.put(TAG_ID, id);
                    contact.put(TAG_PROB, name);
                    contact.put(TAG_DESC, email);
                    contactList.add(contact);

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            Log.e("ServiceHandler", "Couldn't get any data from the url");
        }

        return null;
    }
    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        // Dismiss the progress dialog
        if (pDialog.isShowing())
            pDialog.dismiss();

//What code to write

    }

}

what should i write in onpost method and custom list class

Ticket_list.java

public class Ticket_list extends ArrayAdapter< String> {
HashMap<String, String> objects;
public Ticket_list(Context context, int resource, HashMap<String,String> objects) {
    super(???? //what );

}
   //What



   }

Please help me to write onpost method code and code of Ticket_list

  • where is your custom adapter? – Emil Sep 24 '15 at 06:36
  • first find basic tutorial on list adapter understand it.....and then implement as per you requirement...after that you get error then edit this question with your implementation.... http://www.vogella.com/tutorials/AndroidListView/article.html#adapterown – Shadow Droid Sep 24 '15 at 06:36
  • 1
    possible duplicate of [HashMap to ListView](http://stackoverflow.com/questions/19466757/hashmap-to-listview) – Bö macht Blau Sep 24 '15 at 06:37
  • i dont know how to write that code i am beginner to this so could you please give me the code according to my problem – abhi jaghari Sep 24 '15 at 06:50
  • What to write in onpost method and what code is in customlist class – abhi jaghari Sep 24 '15 at 06:51

1 Answers1

0

I highly recommend you to use RecyclerView instead of ListView and use Retrofit to send request and get the response as json.Take a look at these documents For RecyclerView.

Armin Ghoreishi
  • 56
  • 2
  • 12
  • i dont know how to use recycleview could you slove mt=y problem using custom list view – abhi jaghari Sep 24 '15 at 07:07
  • @abhijaghari Did you look at the Document? It has a fully explanation of recyclerView. RecyclerView is easier than custom listView to learn and use. Please take a look at the Document i've posted above. But if you couldnt understand the concept i'll post some code for cusomt listView. – Armin Ghoreishi Sep 24 '15 at 21:05