解决方案
30
public class Data { private String TotalNumber; private int PageNumber; private int PageSize; private List<DataList> DataList; public String getTotalNumber() { return TotalNumber; } public void setTotalNumber(String totalNumber) { TotalNumber = totalNumber; } public int getPageNumber() { return PageNumber; } public void setPageNumber(int pageNumber) { PageNumber = pageNumber; } public int getPageSize() { return PageSize; } public void setPageSize(int pageSize) { PageSize = pageSize; } public List<Data.DataList> getDataList() { return DataList; } public void setDataList(List<Data.DataList> dataList) { DataList = dataList; } class DataList{ private String Woid; private String Receivealarmtime; private int eleid; private int elekdy; private String sysc; private int wotype; private double longitude; private double lat; private String dispatchtime; public String getWoid() { return Woid; } public void setWoid(String woid) { Woid = woid; } public String getReceivealarmtime() { return Receivealarmtime; } public void setReceivealarmtime(String receivealarmtime) { Receivealarmtime = receivealarmtime; } public int getEleid() { return eleid; } public void setEleid(int eleid) { this.eleid = eleid; } public int getElekdy() { return elekdy; } public void setElekdy(int elekdy) { this.elekdy = elekdy; } public String getSysc() { return sysc; } public void setSysc(String sysc) { this.sysc = sysc; } public int getWotype() { return wotype; } public void setWotype(int wotype) { this.wotype = wotype; } public double getLongitude() { return longitude; } public void setLongitude(double longitude) { this.longitude = longitude; } public double getLat() { return lat; } public void setLat(double lat) { this.lat = lat; } public String getDispatchtime() { return dispatchtime; } public void setDispatchtime(String dispatchtime) { this.dispatchtime = dispatchtime; } } }
上面写错了少写了点
10
Handler handler2 = new Handler(){ public void handleMessage(Message msg) { json = (JSONObject) msg.obj; try { String status = json.getString("status"); String msg1 = json.getString("msg"); //plg.dismiss(); if(status.equals("EEHP_SUCCESS")){ String res = json.getString("data"); jsonData = new JSONObject(res); int total = jsonData.getInt("TotalNumber"); int pagenumber = jsonData.getInt("PageNumber "); int pagesize = jsonData.getInt("PageSize"); JSONArray list = json.getJSONArray("datalist"); for(int i=0;i<list.length();i++){ }本人应该在for循环里怎么封装数组成实体类?
不清楚,接口谁写的问谁,对应的字段值,你就按要求填写就是。
那本人怎么样将数组封装成实体类,再继续调用?
你是说把json转成对象吗?用GSON。
本人做出来了,但是现在要把实体类写到适配器ArrayAdapter里,本人在研究这个,有点不太清楚,有人说要用set,你能帮本人看看吗?
自定义个adapter,最好。
public class WaitOrderActivity extends FragmentActivity { private PullToRefreshLayout pullToRefreshLayout; private ListView listView; private List list1 = new ArrayList(); private List listData = new ArrayList(); private String token = "norunorderlist"; private WaitOrderAdapter waitOrderAdapter; // private JSONArray jsonArray; private JSONObject json, jsonData, jsonDataList; ImageView menu, zhuye; @Override protected void onCreate(Bundle arg0) { // TODO Auto-generated method stub super.onCreate(arg0); setContentView(R.layout.activity_wait_order); listView = (ListView) findViewById(R.id.content_view); pullToRefreshLayout = ((PullToRefreshLayout) findViewById(R.id.refresh_view)); setData(); menu = (ImageView) findViewById(R.id.menu); menu.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub finish(); } }); pullToRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(PullToRefreshLayout pullToRefreshLayout) { } public void onLoadMore(final PullToRefreshLayout pullToRefreshLayout) { // TODO Auto-generated method stub new Thread() { public void run() { // getData1(); getData1(); }; }.start(); ; } }); listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub // BusinessVo bov = (BusinessVo) listData.get(position); // //Toast.makeText(BActivity.this, bov.getbName(), // Toast.LENGTH_SHORT).show(); // Intent intent = new // Intent(BActivity.this,Activity_shangpinxaingqing.class); // intent.putExtra("name", bov.getbName()); // intent.putExtra("tel", bov.getTel()); // intent.putExtra("address", bov.getAddress()); // intent.putExtra("img_src", bov.getImgFile()); // intent.putExtra("describe", bov.getshangjiaxiangqing()); // startActivity(intent); Intent intent = new Intent(); intent.setClass(WaitOrderActivity.this, WaitOrderDetailedActivity.class); startActivity(intent); } }); setData(); } void setData() { new Thread() { @SuppressWarnings("deprecation") public void run() { SharedPreferences sharedPreferences = getSharedPreferences("test", Activity.MODE_PRIVATE); // 使用getString方法获得value,注意第2个参数是value的默认值 String _token = sharedPreferences.getString("token", ""); String userId = sharedPreferences.getString("userId", ""); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("userid", userId)); params.add(new BasicNameValuePair("page", "1")); params.add(new BasicNameValuePair("rows", "20")); params.add(new BasicNameValuePair("longitudelat", "30.5")); String url = BaseApplication.url + "norunorderlist"; String kk = PostRequest.Post(url, params, _token); try { json = new JSONObject(kk); Message msg = new Message(); msg.obj = json; handler.sendMessage(msg); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.start(); } Handler handler2 = new Handler() { public void handleMessage(Message msg) { json = (JSONObject) msg.obj; try { String status = json.getString("status"); String msg1 = json.getString("msg"); // plg.dismiss(); if (status.equals("EEHP_SUCCESS")) { String res = json.getString("data"); jsonData = new JSONObject(res); int total = jsonData.getInt("TotalNumber"); int pagenumber = jsonData.getInt("PageNumber "); int pagesize = jsonData.getInt("PageSize"); JSONArray list = json.getJSONArray("datalist"); for (int i = 0; i < list.length(); i++) { OrderList datalist = new OrderList(); JSONObject str = (JSONObject) list.get(i); datalist.setWoid(str.getString("woid")); datalist.setReceivealarmtime(str.getString("Receivealarmtime")); datalist.setEleidCode(str.getString("eleidcode")); datalist.setElekdy(str.getString("Elekdy")); datalist.setSysc(str.getString("Sysc")); datalist.setWotype(str.getInt("Wotype")); datalist.setLongitude(str.getDouble("Longitude")); datalist.setLat(str.getDouble("Lat")); datalist.setDistance(str.getDouble("distance")); list1.add(datalist); } waitOrderAdapter = new WaitOrderAdapter(WaitOrderActivity.this, list1); listView.setAdapter(waitOrderAdapter); } else { } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }; }; private void getData() { listData.clear(); for (int i = 0; i < 10; i++) { listData.add("" + i); } Message message = new Message(); // message.what = 0; message.obj = listData; handler.sendMessage(message); } private void getData1() { listData.clear(); for (int i = 0; i < 10; i++) { // SearchVo searchVo = new SearchVo(); // searchVo.setName("加载数据"+i); // searchVo.setSum(i+""); listData.add("" + i); } Message message = new Message(); // message.what = 0; message.obj = listData; message.arg1 = 1; handler1.sendMessage(message); } Handler handler1 = new Handler() { @Override public void handleMessage(Message msg) { // if(msg.arg1==0){ // listData=(List) msg.obj; // // myAdapter.notifyDataSetChanged(); // // 千万别忘了告诉控件刷新完毕了哦! // pullToRefreshLayout.refreshFinish(PullToRefreshLayout.SUCCEED); // } if (msg.arg1 == 1) { listData = (List) msg.obj; list1.addAll(listData); waitOrderAdapter.notifyDataSetChanged(); pullToRefreshLayout.loadmoreFinish(PullToRefreshLayout.SUCCEED); } } }; Handler handler = new Handler() { public void handleMessage(Message msg) { listData = (List) msg.obj; list1.clear(); list1.addAll(listData); waitOrderAdapter = new WaitOrderAdapter(WaitOrderActivity.this, list1); listView.setAdapter(waitOrderAdapter); pullToRefreshLayout.refreshFinish(PullToRefreshLayout.SUCCEED); }; }; }上面是本人的代码
下面是本人要适配的适配器package com.eehp.adapter; import java.util.List; import com.eehp.R; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; public class WaitOrderAdapter extends ArrayAdapter{ private List list; private View view; public WaitOrderAdapter(Context context, List list) { super(context, 0, list); // TODO Auto-generated constructor stub this.list = list; } @Override public int getCount() { // TODO Auto-generated method stub return list.size(); } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub view = LayoutInflater.from(getContext()).inflate(R.layout.list_item_fragment, null); return view; } }适配器里本人该怎么写啊
list不就是你的数据源嘛,你要在item上显示什么数据,就在你加载的布局中找到对应view,赋值就可以了。
网上有很多例子,你可以找着看看。