标签:idt top .com void xtend not fresh 官网 string
第一步:到官网下载第三方包,拷贝到自己的项目中
https://github.com/Maxwin-z/XListView-Android
第二步:xml文件
<me.maxwin.view.XListView android:id="@+id/xListView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#00000000"> </me.maxwin.view.XListView>
第三步:java代码
package com.gcp; import java.util.ArrayList; import me.maxwin.view.XListView; import me.maxwin.view.XListView.IXListViewListener; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.widget.ArrayAdapter; public class XListViewActivity extends Activity implements IXListViewListener { private XListView mListView; //创建XListView对象 private ArrayAdapter<String> mAdapter; private ArrayList<String> items = new ArrayList<String>(); private Handler mHandler; //用来模拟网络请求的(不要被迷惑) private int start = 0; private static int refreshCnt = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); geneItems(); mListView = (XListView) findViewById(R.id.xListView); mListView.setPullLoadEnable(true);//上拉刷新 mAdapter = new ArrayAdapter<String>(this, R.layout.list_item, items);//用模拟的数据填充系统的adapter mListView.setAdapter(mAdapter);//指定adapter // mListView.setPullLoadEnable(false); // mListView.setPullRefreshEnable(false);//下拉刷新 mListView.setXListViewListener(this); //给xListView条目设置监听事件 mHandler = new Handler(); } private void geneItems() { for (int i = 0; i != 5; ++i) { items.add("refresh cnt " + (++start)); } } //或的数据后一定要加onLoad()方法,否则刷新会一直进行,根本停不下来 private void onLoad() { mListView.stopRefresh(); mListView.stopLoadMore(); mListView.setRefreshTime("刚刚"); } @Override public void onRefresh() { mHandler.postDelayed(new Runnable() { @Override public void run() { start = ++refreshCnt; items.clear(); geneItems(); // mAdapter.notifyDataSetChanged(); mAdapter = new ArrayAdapter<String>(XListViewActivity.this, R.layout.list_item, items); mListView.setAdapter(mAdapter); onLoad(); } }, 2000); } @Override public void onLoadMore() { mHandler.postDelayed(new Runnable() { @Override public void run() { geneItems(); mAdapter.notifyDataSetChanged(); onLoad(); } }, 2000); } }
标签:idt top .com void xtend not fresh 官网 string
原文地址:http://www.cnblogs.com/ganchuanpu/p/6072206.html