使用HttpUTILS请求XML数据
来源:互联网 发布:户外广告行业数据 编辑:程序博客网 时间:2024/06/05 21:11
public class BKFragments extends Fragment implements IXListViewListener{
private XListView lv;
private HttpUtils httpUtils;
private int num=0;
private List<BlogBean> list;
private Handler handler;
private boolean flag;
private boolean tag;
private BKAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_selection_common,
container, false);
lv = (XListView) rootView.findViewById(R.id.lv);
return rootView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
lv.setPullLoadEnable(true);
httpUtils = new HttpUtils();
// 获取网络数据
startHttpUtils(num);
// 设置监听
lv.setXListViewListener(this);
handler = new Handler();
}
private void startHttpUtils(int id) {
String path="http://www.oschina.net/action/api/blog_list?type=latest&pageIndex="+id+"&pageSize=20";
httpUtils.send(HttpMethod.GET, path, new RequestCallBack<String>() {
@Override
public void onFailure(HttpException arg0, String arg1) {
System.out.println("请求失败");
}
@Override
public void onSuccess(ResponseInfo<String> weResponseInfo) {
String data = weResponseInfo.result;
List<BlogBean> lists = new PullUtils().getBoKelist(data);
System.out.println(lists);
if(flag==true){
System.out.println("头部加载");
list.addAll(0, lists);
}else{
if(tag==false){
System.out.println("首次加载");
tag=true;
list=lists;
}else{
System.out.println("尾部加载");
list.addAll(lists);
}
}
setData();
}
});
}
protected void setData() {
adapter = new BKAdapter(getActivity(),list);
lv.setAdapter(adapter);
}
private void onLoad() {
lv.stopRefresh();
lv.stopLoadMore();
lv.setRefreshTime("刚刚");
}
@Override
public void onRefresh() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
flag=true;
num +=1;
startHttpUtils(num);
adapter.notifyDataSetChanged();
onLoad();
}
}, 2000);
}
@Override
public void onLoadMore() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
flag=false;
num +=1;
startHttpUtils(num);
adapter.notifyDataSetChanged();
onLoad();
}
}, 2000);
}
}
private XListView lv;
private HttpUtils httpUtils;
private int num=0;
private List<BlogBean> list;
private Handler handler;
private boolean flag;
private boolean tag;
private BKAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_selection_common,
container, false);
lv = (XListView) rootView.findViewById(R.id.lv);
return rootView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
lv.setPullLoadEnable(true);
httpUtils = new HttpUtils();
// 获取网络数据
startHttpUtils(num);
// 设置监听
lv.setXListViewListener(this);
handler = new Handler();
}
private void startHttpUtils(int id) {
String path="http://www.oschina.net/action/api/blog_list?type=latest&pageIndex="+id+"&pageSize=20";
httpUtils.send(HttpMethod.GET, path, new RequestCallBack<String>() {
@Override
public void onFailure(HttpException arg0, String arg1) {
System.out.println("请求失败");
}
@Override
public void onSuccess(ResponseInfo<String> weResponseInfo) {
String data = weResponseInfo.result;
List<BlogBean> lists = new PullUtils().getBoKelist(data);
System.out.println(lists);
if(flag==true){
System.out.println("头部加载");
list.addAll(0, lists);
}else{
if(tag==false){
System.out.println("首次加载");
tag=true;
list=lists;
}else{
System.out.println("尾部加载");
list.addAll(lists);
}
}
setData();
}
});
}
protected void setData() {
adapter = new BKAdapter(getActivity(),list);
lv.setAdapter(adapter);
}
private void onLoad() {
lv.stopRefresh();
lv.stopLoadMore();
lv.setRefreshTime("刚刚");
}
@Override
public void onRefresh() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
flag=true;
num +=1;
startHttpUtils(num);
adapter.notifyDataSetChanged();
onLoad();
}
}, 2000);
}
@Override
public void onLoadMore() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
flag=false;
num +=1;
startHttpUtils(num);
adapter.notifyDataSetChanged();
onLoad();
}
}, 2000);
}
}
0 0
- 使用HttpUTILS请求XML数据
- httpUtils请求XML数据
- HttpUtils请求数据
- HttpUtils请求数据
- HttpUtils请求数据
- httputils请求数据
- 通过httpUtils请求网络xml数据进行解析
- HttpUtils解析xml数据
- HttpUtils 请求数据(pull)
- HttpUtils 请求数据(json)
- Httputils请求数据Pull解析
- HttpUtils请求XML文件,XStream解析
- HttpUtils请求XML加XListView刷新加载
- 第三方的httputils请求数据和xml的pull解析
- Pull解析xml文件,并用HttpUtils请求数据接口(示例方法)
- HttpUtils请求
- HttpURLConnection、HttpClient请求网络数据、Xutils的HttpUtils 请求数据
- 使用HttpURLConnection请求XML数据
- 使用Messenger实现IPC通信
- 2>&1 的用法说明。
- 深入理解Android的startservice和bindservice
- web magic
- HDU 2952 Counting Sheep 深搜
- 使用HttpUTILS请求XML数据
- 用户态文件系统fuse学习
- 欢迎使用CSDN-markdown编辑器
- C#重写Equals()
- 一次Ajax报错:“存储空间不足,无法完成此操作”的解决经验
- Keras学习日记1
- zencart 安装和配置修改笔记
- Lombok学习
- C语言运算符和操作符