package com.example.testxml1;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import me.maxwin.view.XListView;
import me.maxwin.view.XListView.IXListViewListener;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.example.adapter.MyBAdapter;
import com.example.bean.Bean;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

import android.os.Bundle;
import android.os.Handler;
import android.widget.ListView;
import android.R.integer;
import android.app.Activity;

public class MainActivity extends Activity implements IXListViewListener{
private HttpUtils httpUtils;
private List<Bean> lists = new ArrayList<Bean>();
private List<Bean> listss;
private XListView xlistView;
private int start1 = 12;
private Handler handler;
private MyBAdapter adapter;
private static int refereshCnt = 0 ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xlistView = (XListView) findViewById(R.id.xlistview);
xlistView.setPullLoadEnable(true);
xlistView.setPullRefreshEnable(true);
xlistView.setXListViewListener(this);
for (int i = 11; i != start1; i++) {
getdata(start1);
}
adapter = new MyBAdapter(lists, MainActivity.this);
xlistView.setAdapter(adapter);
handler = new Handler();
}
private void getdata(int start) {
httpUtils = new HttpUtils();
httpUtils.send(HttpMethod.GET, "http://v.juhe.cn/laohuangli/h?date=2014-09-"+start+"&key=8097aa39feea4ac842b05424e9de355a&dtype=xml", new RequestCallBack<String>() {
@Override
public void onFailure(HttpException arg0, String arg1) {
// TODO Auto-generated method stub

}
@Override
public void onSuccess(ResponseInfo<String> arg0) {
// TODO Auto-generated method stub
String uri = arg0.result;
try {
InputStream is = new ByteArrayInputStream(uri.getBytes());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(is);
Element element = document.getDocumentElement();
NodeList list = element.getElementsByTagName("item");
for (int i = 0; i < list.getLength(); i++) {
Bean b = new Bean();
Element e = (Element) list.item(i);
b.setYangli(e.getElementsByTagName("yangli").item(0).getTextContent());
b.setHours(e.getElementsByTagName("hours").item(0).getTextContent());
b.setDes(e.getElementsByTagName("des").item(0).getTextContent());
b.setYi(e.getElementsByTagName("yi").item(0).getTextContent());
b.setJi(e.getElementsByTagName("ji").item(0).getTextContent());
lists.add(b);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
@Override
public void onRefresh() {
// TODO Auto-generated method stub
handler.postDelayed(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
start1 = ++refereshCnt;
lists.clear();
getdata(start1);
adapter.notifyDataSetChanged();
onLoad();
}
}, 2000);
}
@Override
public void onLoadMore() {
// TODO Auto-generated method stub
handler.postDelayed(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
getdata(start1);
adapter.notifyDataSetChanged();
onLoad();
}
}, 2000);
}

public void onLoad() {
// TODO Auto-generated method stub
xlistView.stopLoadMore();
xlistView.stopRefresh();
xlistView.setRefreshTime("刚刚");
};
}

XListView理念的更多相关文章

  1. atitit.attilax的软件 架构 理念.docx

    atitit.attilax的软件 架构 理念.docx 1. 预先规划.1 2. 全体系化1 3. 跨平台2 4. 跨语言2 5. Dsl化2 5.1. 界面ui h5化2 6. 跨架构化2 7. ...

  2. 女生的最爱,装饰品。WPF也有,Adorner。(上海晒衣服理念)

    说到装饰,不由要说到女性. 去年过年回家给我妈买了周大福项链,很明显就感觉待遇就不一样了,即使这样,还是被一个阿姨说应该买更重点的.看来钱这种东西果然是多一点才好.虽然自己无所谓,但让家里人更开心也是 ...

  3. 【翻译】理念:无冲突的扩展本地DOM原型

    菜鸟翻译,望大家多多指正哈 原文:http://lea.verou.me/2015/04/idea-extending-native-dom-prototypes-without-collisions ...

  4. 张艾迪(创始人):Be.Time+Cr.Idear的创新理念

    The World No.1 Girl :Eidyzhang The World No.1 Internet Girl :Eidyzhang AOOOiA.global Founder :Eidyzh ...

  5. XListView

    第一步:到官网下载第三方包,拷贝到自己的项目中 https://github.com/Maxwin-z/XListView-Android 第二步:xml文件 <me.maxwin.view.X ...

  6. android第三方框架 xlistview 的使用

    如今上拉刷新,下拉加载更多已经是浩如烟海的app的标配了 最近正好有相关的需要就去学习了一下,还是那句老话凡事都靠自己来 搞实在不是一件好事,费时费力不说可能还是在做无用功,不过自己研究学习 还是很有 ...

  7. XListView刷新

    package com.example.da; import java.util.ArrayList;import java.util.List; import com.badu.net.Networ ...

  8. paip.多维理念 输入法的外码输入理论跟文字输出类型精髓

    paip.多维理念 输入法的外码输入理论跟文字输出类型精髓 通常,我们的输入法使用的外码是拼音,但是,这个的用户体验很差.. 应该使用多个外码类型... ##按照词汇来源,有如下几个 固有词ati 来 ...

  9. paip.元数据驱动的转换-读取文件行到个list理念 uapi java php python总结

    paip.元数据驱动的转换-读取文件行到个list理念 uapi java php python总结 #两个思路 1.思路如下:使用file_get_contents()获取txt文件的内容,然后通过 ...

随机推荐

  1. windows系统调用 利用事件对象实现进程通信

    #include "iostream" #include "windows.h" #include "cstring" using name ...

  2. ECMAScript 6教程 (一)

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出 原文连接,博客地址为 http://www.cnblogs.com/jasonnode/ .该系列课程是 ...

  3. startssl,免费的ssl证书申请及注意事项

    免费的ssl证书,https://www.startssl.com/ 安装到IIS和Nginx有所不同.原文 http://blog.newnaw.com/?p=1232 ------------转自 ...

  4. 扩大Tomcat内存

    在Eclipse里选:Window->Preference->Installed JREs->Edit(选中jre),在Default VM Arguments里输入-Xms256m ...

  5. TextBox

    一.聚焦: private void FrmOnlineChargeMoney_Paint(object sender, PaintEventArgs e) { edtAuthCode.SelectA ...

  6. LeetCode----8. String to Integer (atoi)(Java)

    package myAtoi8; /* * Implement atoi to convert a string to an integer. Hint: Carefully consider all ...

  7. 安装Ifconfig

    1.ifconfig 2.whereis 检查 3.yum search ifconfig 4.分割线下面让我们安装 net-tools.x86_64 执行 yum -y install net-to ...

  8. redis安装与基本配置

    获取下载包 wget http://download.redis.io/releases/redis-2.8.24.tar.gz 解压和编译 tar -zxvf redis-2.8.24.tar.gz ...

  9. shell & dialog

    最近使用dialog写图形自动化shell脚本,  功能很强大,功能不是非常多但是足够用.想写一篇linux下dialog的使用方法,虽然命令不多,但是写起来也需要下很大功夫,而且不一定写得更好,在网 ...

  10. [问题2014A13] 解答

    [问题2014A13]  解答 先引入两个简单的结论. 结论 1  设 \(\varphi\) 是 \(n\) 维线性空间 \(V\) 上的线性变换, 若存在正整数 \(k\), 使得 \(\math ...