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. 使用plsql执行计划进行sql调优(转载)

    一段SQL代码写好以后,可以通过查看SQL的执行计划,初步预测该SQL在运行时的性能好坏,尤其是在发现某个SQL语句的效率较差时,我们可以通过查看执行计划,分析出该SQL代码的问题所在. 那么,作为开 ...

  2. 在linux中安装adb和fastboot工具

    我用的是archlinux,在官方的软件仓库里就可以找到对应的包,包的名字叫:android-tools 据说debian系列的软件包是两个,分别是:android-tools-adb, androi ...

  3. REPL LOG

    using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressi ...

  4. C#知识点有必要知会

    如果说你父类里面有一个成员比如int a;那么你子类里面也可以再定义一个int a,这个时候base.a和this.a表示的就不是一个变量了,如果说子类里面没有,那么base.a和this.a表示的都 ...

  5. php将抓取的图片链接下载到本地

    备注: fclose这一步操作完成之后如果返回值是空表示下载成功,否则会返回1或者其他错误提示 这个步骤测试的时候实在yii2框架的基础上执行的,下载到的图片实在frontend目录下的web目录下( ...

  6. Java 引用传递

    按照Java的规定,Java的函数参数在传递的时候有两种方式. 对于基本类型,如int,double等作为函数参数传递时,采取的是传值方式. 对于对象,如数组.字符串等作为参数传递时,采用的是引用方式 ...

  7. 【原创】js中利用cookie实现记住密码功能

    在登录界面添加记住密码功能,我首先想到的是在java后台中调用cookie存放账号密码,大致如下: HttpServletRequest request HttpServletResponse res ...

  8. [转]使用xcode4 workspace 多个project协同工作

    转载地址:http://erlangprogram.com/use-xcode4-workspace   一般的某个应用单独新建一个 project 就可以了,然后把所有的程序文件都放在里面,这个可以 ...

  9. 游戏引擎PushButtonEngine简介

    PushButtonEngine是一个开源的模块化游戏引擎,你可以通过https://github.com/PushButtonLabs/PushButtonEngine得到其代码和相关文档.下面我将 ...

  10. 【Linux命令与工具】磁盘与目录的容量——df和du

    df(disk free):列出文件系统的整体磁盘使用量 用法: df [-akmhi] [目录或文件名] 参数: -a: 列出所有的文件系统,包括系统特有的/proc等文件系统 -k: 以KB的容量 ...