对Volley框架的一些接口进行封装:VolleyAir
简介
VolleyAir是在著名的谷歌开源的网络框架Volley的基础上进行的二次封装,并吸取了VolleyPlus的一些封装经验,使之能更有效 的在复杂的数据处理逻辑层进行网络请求,使逻辑层的代码更加清爽简洁。之所以选择Volley进行封装,是因为Volley是一款极为高效的网络请求框 架,并且开发自谷歌的Android团队。在其基础上封装适配过后,将更为有利于我们的应用开发。

使用方法
1.根据自己的业务需求,,在NetworkMoudle类中自定义请求地址以及参数
public TaskHandle arrangeGetNewsList(String requestTag, String cty, String category, int page, int row, String title) {
HttpRequest request = new HttpRequest(API_URL + "news/getNews");
request.addParameter("cty", cty);
request.addParameter("category", category);
request.addParameter("page", Integer.toString(page));
request.addParameter("row", Integer.toString(row));
request.addParameter("title", title);
request.setRequestTag(requestTag);
return center.arrange(request, volleyPostString);
} 2.根据自己的业务需求,在DataMoudle类中自定义如何解析接收到的网络数据
public IDData parseNewsList() throws HttpProcessException {
try {
JSONObject json = tryExtra(JSONObject.class);
IDData data = new IDData(json.optInt("count", -1), null);
JSONArray array = json.optJSONArray("data");
ArrayList<NewsListItem> list = new ArrayList<NewsListItem>(array == null ? 0 : array.length());
data.data = list;
if (null != array) {
NewsListItem item;
for (int i = 0; i < array.length(); ++i) {
json = array.getJSONObject(i);
item = new NewsListItem();
item.id = json.optString("id");
item.title = json.optString("title");
item.create_time = json.optString("create_time");
item.img = json.optString("img");
item.category_name = json.optString("category_name");
item.city_name = json.optString("city_name");
item.description = json.optString("description");
list.add(item);
}
}
extra = data;
return data;
} catch (Exception e) {
throw badResponseException(e);
}
} 3.让View层(Activity、Fragment等)实现网络数据接收器接口
public class MainActivity extends AppCompatActivity implements Receiver<DataModule>
相关推荐
lolafon 2015-04-18
狂草 2015-12-31
俊光 2018-08-10
scuzoutao 2015-04-02
Garment 2019-06-21
OliverLau 2019-06-21
SnailDream 2019-06-21
newtrekWang 2019-06-20
scuzoutao 2019-06-20
狂草 2019-06-20
doomvsjing 2019-06-11
hh000 2017-04-10
scuzoutao 2017-03-30
狂草 2016-09-12
JewelCCL 2016-08-10
Garment 2016-08-10
magic00 2016-08-10
scuzoutao 2016-05-10
SnailDream 2016-03-21