new Thread() {
@Override
public void run() {
// TODO Auto-generated method stub
Looper.prepare();
String urlPath = Url.myURL4();
URL url;
try {
url = new URL(urlPath);
JSONObject ClientKey = new JSONObject();
ClientKey.put("c_hc_id", imei);
ClientKey.put("c_no", "000032");
ClientKey.put("c_sdt", startTime);
ClientKey.put("c_edt", endTime);
ClientKey.put("c_storeid", "101");
String content = String.valueOf(ClientKey);
Log.e("流水查询发送数据", content + "");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("ser-Agent", "Fiddler");
conn.setRequestProperty("Content-Type", "application/json");
OutputStream os = conn.getOutputStream();
Log.e("流水查询os", "0000000" + os);
os.write(content.getBytes());
os.close();
int code = conn.getResponseCode();
Log.e("流水查询code", code + "");
if (code == 200) {
Toast.makeText(BranchHistoricalActivity.this, "查询数据", Toast.LENGTH_SHORT).show();
InputStream is = conn.getInputStream();
String json = NetUtils.readString(is);
Log.e("流水查询获取返回的数据", json + "");
BranchHistoricalActivity.this.invalidateOptionsMenu();
//使用fastjson
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(json);
com.alibaba.fastjson.JSONArray jsonArray = jsonObject.getJSONArray("data");
shanghuXiaoShouBeans = jsonArray.parseArray(jsonArray.toString(), ShanghuXiaoShouBean.class);
Log.e("shanghuXiaoShouBeans", shanghuXiaoShouBeans + "");
} else {
Toast.makeText(getApplicationContext(), "数据提交失败", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "数据提交失败", Toast.LENGTH_SHORT).show();
}
Looper.loop();
}
}.start();
public class ListviewAdapter extends BaseAdapter{
private List datas ;//你的数据集合
private Context context ;
public ListviewAdapter(List datas , Context context) {
this.datas = datas;
this.context = context;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
String data = datas.get(i);
ViewHolder holder = new ViewHolder();
if(view == null){
view = LayoutInflater.from(context).inflate(R.layout.recycler_view,null);
holder.photo = (ImageView) view.findViewById(R.id.iv_photo);
holder.tvTitle = (TextView) view.findViewById(R.id.tv_title);
holder.tvContent = (TextView) view.findViewById(R.id.tv_content);
view.setTag(holder);
}
holder = (ViewHolder) view.getTag();
holder.photo.setImageResource(R.mipmap.ic_launcher);
holder.tvTitle.setText(data);
holder.tvContent.setText(data);
return view ;
}
@Override
public int getCount() {
return datas.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
private class ViewHolder {
ImageView photo ;
TextView tvTitle;
TextView tvContent;
}
}
需要适配器 item 需要将数据放在item里面通过适配器放入listview 不知道说的对不对
jsonArray 就是你获得的数据集合。你把它绑定到Listview上去。 提出你要展示的数据。。
shanghuXiaoShouAdapter = new MyAdapter(BranchHistoricalActivity.this, context, shanghuXiaoShouBeans, m_listMLv)
m_listMlv.setAdapter(shanghuXiaoShouAdapter);
这样绑定吗?context参数一直是红色,错误啊
context这个可以不要了吧,你已经传了BranchHistoricalActivity.this就可以拉