Volley框架使用笔记
2016-06-17 11:23
176 查看
1、使用get请求时候
StringRequest(method, url, listener, errorListener)
第一个参数method为选择方式 Method.GET
第二个参数url为String字符串的网络地址
第三个参数listener为Listener<String>(){重写onResponse(String response)方法,返回获得的String字符串}
第四个参数errorListener为Response.ErrorListener(){重写onErrorResponse(VolleyError error)数据请求失败调用}
JsonObjectRequest(method, url, jsonRequest, listener, errorListener)
第一个参数method为选择方式 Method.GET /POST
第二个参数url为String字符串的网络地址
第二个参数jsonRequest为post请求时候传入的json字符串
第三个参数listener为Listener<String>(){重写onResponse(String response)方法,返回获得的String字符串}
第四个参数errorListener为Response.ErrorListener(){重写onErrorResponse(VolleyError error)数据请求失败调用}
2、POST请求
JsonObjectRequest(method, url, jsonRequest, listener, errorListener)
JsonObjectRequest只需要给jsonRequest放入一个值,改Method.postMap<String, String> hashMap=new HashMap<String,String>();
hashMap.put("username", "xiaowen@redbaby.com.cn");
hashMap.put("password", "123456");
JSONObject object=new JSONObject(hashMap);
StringRequest(method, url, listener, errorListener)
则需要重写getParams()方法,传入值protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> hashMap=new HashMap<String,String>();
hashMap.put("username", "xiaowen@redbaby.com.cn");
hashMap.put("password", "123456");
return hashMap;
}
3、请求图片
ImageRequest(url, listener, maxWidth, maxHeight, decodeConfig, errorListener)
第一个参数url为String字符串的网络地址
第二个参数listener为Listener<Bitmap>(){重写onResponse(Bitmapresponse)方法,返回获得的String字符串}
第三第四个参数加载图片的最大宽高(0,0为原图)
第五个参数decodeConfig为图片的格式(Config.RGB_565)
第六个参数errorListener为Response.ErrorListener(){重写onErrorResponse(VolleyError error)数据请求失败调用}
相关文章推荐
- Linux Kernel Namespace实现: namespace API介绍
- ssl
- Maven如何手动添加依赖的jar文件到本地Maven仓库
- Leetcode 213. House Robber II
- 解决SearchController.searchbar的问题
- Outlook客户端和Exchange服务器连接问题排错常用工具——Office配置扫描
- javascript日期比较方法实例分析
- 注解机制及其原理
- 注解机制及其原理
- ubuntu使用ssh连接远程电脑的方法
- 神经语言程序学的十二条前提假设
- 理解c语言中的void*用法
- Arduino ide 1.6.9 遇到的问题 error: 'TKD2' was not declared in this scope
- Java中的自动装箱与拆箱
- Android TransitionDrawable ImageView过度效果使用实例
- AWS连接Linux
- 预示敏捷方法走偏的15个标志——第2部分
- Coin Change
- hbase学习笔记
- Linux常见基础命令总结(二)