【发布时间】:2015-12-21 16:01:44
【问题描述】:
我想在 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
}
}
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
}
请帮我写onpost方法代码和Ticket_list的代码
【问题讨论】:
-
您的自定义适配器在哪里?
-
首先找到关于列表适配器的基本教程理解它......然后根据你的要求实施......之后你得到错误然后用你的实施编辑这个问题......@987654321 @
-
HashMap to ListView的可能重复
-
我不知道如何编写代码我是初学者,所以请你根据我的问题给我代码
-
onpost方法里写什么,customlist类里有什么代码
标签: android