首页 > 代码库 > XListView
XListView
第一步:到官网下载第三方包,拷贝到自己的项目中
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 onl oad() { 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); onl oad(); } }, 2000); } @Override public void onl oadMore() { mHandler.postDelayed(new Runnable() { @Override public void run() { geneItems(); mAdapter.notifyDataSetChanged(); onl oad(); } }, 2000); } }
XListView
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。