// 加载图片 private void imageLoader_cache(ImageView imageView, String pic) { // 设置 图片缓存 :体现 imageLoader的优势 // 使用 LruBitmap + ImageCache 实现 // 实例化对象 ImageLoader imageLoader = new ImageLoader(VolleyApplication.getQueue(), new VolleyBitmapCache()); // 图片监听 (默认图片,错误图片) 和 imageView ImageListener imageListener = ImageLoader.getImageListener(imageView, R.drawable.ic_launcher, R.drawable.ic_launcher); // 加载图片 后面可以设置 图片的大小缩放 imageLoader.get(VolleyHttpPath.getBasicPath() + "/" + pic, imageListener, 0, 0); }
private void getMovieList() { String url = VolleyHttpPath.getSharedAll(); Show(url); JsonObjectRequest objectRequest = new JsonObjectRequest( Method.POST, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { // 设置参数 List<shared> list = new ArrayList<shared>(); String str = "网络错误"; try { if (response.getString("msg").equals("success") && response.getInt("code") == 1) { // json解析 为 List<shared> JSONArray array = new JSONArray(response.getString("data")); for (int i = 0; i < array.length(); i++) { JSONObject object = (JSONObject) array.get(i); shared s = new shared(); s.setId(object.getInt("id")); s.setName(object.getString("name")); s.setPic(object.getString("pic")); s.setTotol(object.getString("totol")); list.add(s); } if (list.size() > 0) { // 解析完毕 ,适配 listview MovieListAdapter adapter = new MovieListAdapter(list); move_list.setAdapter(adapter); } else { str = "没有解析出来" + response.toString(); Show(str); } } else { Show(response.getString("msg")); } } catch (JSONException e) { // 发生异常 Show(e.getMessage()); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // 失败 Show(error.getMessage()); } }); // 一定添加到队列中 objectRequest.setTag("movieList"); VolleyApplication.getQueue().add(objectRequest); }