Android 带有hashmap的Listview

Android 带有hashmap的Listview,android,Android,我想在listview中显示服务器json响应。我在hashmap中获得了所有值。我对如何在自定义listview中设置该数据感到困惑。请帮助我并向我展示代码 class viewticket extends AsyncTask<Void, Void, Void> { @Override protected void onPreExecute() { super.onPreExecute(); pdialog = new Progre

我想在listview中显示服务器json响应。我在hashmap中获得了所有值。我对如何在自定义listview中设置该数据感到困惑。请帮助我并向我展示代码

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

    }

}
class viewticket扩展异步任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pdialog=newprogressdialog(UserLogedIn.this);
pdialog.setMessage(“加载…”);
pdialog.setUndeterminate(假);
pdialog.setCancelable(假);
pdialog.show();
}
@凌驾
受保护的Void doInBackground(Void…参数){
List param=new ArrayList();
参数add(新的BasicNameValuePair(“userid”,u_id));
JSONObject jsonArray=jpar.makeHttpRequest(URLMyTicket,“POST”,param);
ServiceHandler sh=新的ServiceHandler();
//向url发出请求并获得响应
字符串jsonStr=sh.makeServiceCall(URLMyTicket,ServiceHandler.POST,param);
Log.d(“响应:”、“>”+jsonStr);
if(jsonStr!=null){
试一试{
联系人=新的JSONArray(jsonStr);
int a=contacts.length();
对数v(标签““+a”);
对于(int i=0;i
我应该在onpost方法和自定义列表类中编写什么

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



   }
public class Ticket\u列表扩展了ArrayAdapter{
HashMap对象;
公共票证列表(上下文、int资源、HashMap对象){
超级(????//什么);
}
//什么
}

请帮助我编写onpost方法代码和票证列表代码

我强烈建议您使用而不是ListView,并使用来发送请求和获取json响应。请查看这些文档。

我强烈建议您使用而不是ListView,并使用来发送请求和获取json响应。请查看这些文档适用于。

您的自定义适配器在哪里?首先在列表适配器上找到基本教程了解它…然后根据您的要求实施…之后您会发现错误,然后使用您的实施编辑此问题。。。。可能重复的我不知道如何编写代码我是初学者,所以你能根据我的问题给我代码吗?在onpost方法中编写什么,在customlist类中有什么代码?你的自定义适配器在哪里?首先找到关于list adapter的基本教程了解它…然后根据你的要求实现…之后您得到错误,然后用您的实现编辑此问题。。。。可能重复我不知道如何编写代码我是这方面的初学者,所以请你根据我的问题给我代码。在onpost方法中编写什么,在customlist Classis中编写什么代码。我不知道如何使用recycleview。你能用custom list解决mt=y问题吗view@abhijaghari你看过文件了吗?它对recyclerView有充分的解释。RecyclerView比自定义listView更易于学习和使用。请看一下我上面贴的文件。但是如果你不能理解这个概念,我会发布一些cusomt listView的代码。我不知道如何使用recycleview。你能用自定义列表解决mt=y的问题吗view@abhijaghari你看过文件了吗?它对recyclerView有充分的解释。RecyclerView比自定义listView更易于学习和使用。请看一下我上面贴的文件。但是如果你不理解这个概念,我会发布一些cusomt listView的代码。