XListView上拉刷新下拉加载(按两下能退出)
来源:互联网 发布:ios wkwebview 和 js 编辑:程序博客网 时间:2024/06/08 16:26
drawable文件,xml布局文件没写
Mactivity中
package com.example.aa;import java.util.ArrayList;import java.util.List;import com.example.utils.SimpleDataExample;import com.example.utils.XListView;import com.example.utils.XListView.IXListViewListener;import android.app.Activity;import android.os.Bundle;import android.view.KeyEvent;import android.widget.ListView;import android.widget.Toast;public class MainActivity extends Activity implements IXListViewListener { List<Person> al = new ArrayList<Person>(); private MyAdapter adapter; private XListView xlistView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); xlistView = (XListView) findViewById(R.id.listView); adapter = new MyAdapter(this); xlistView.setAdapter(adapter); // 添加XListView的上拉和下拉刷新监听器 xlistView.setPullLoadEnable(true); xlistView.setPullRefreshEnable(true); xlistView.setXListViewListener(this); addList(); adapter.addrest(al); } private void addList() { for (int i = 0; i < 10; i++) { Person person = new Person(); person.name = "李明" + i; al.add(person); } } // 下拉刷新 @Override public void onRefresh() { al.clear(); addList(); adapter.addrest(al); SimpleDataExample.setFormat("dddddddddddd", getApplicationContext()); SimpleDataExample.getFormat("dddddddddddd", getApplicationContext(), xlistView); } // 上拉加载 @Override public void onLoadMore() { addList(); adapter.addrest(al); SimpleDataExample.setFormat("dddddddddddd", getApplicationContext()); SimpleDataExample.getFormat("dddddddddddd", getApplicationContext(), xlistView); }//一下是两次点击返回键退出 private long mExitTime; public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { if ((System.currentTimeMillis() - mExitTime) > 2000) { Object mHelperUtils; Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show(); mExitTime = System.currentTimeMillis(); } else { finish(); } return true; } return super.onKeyDown(keyCode, event); }}
MyAdapter类 中
package com.example.aa;import java.util.ArrayList;import java.util.List;import android.content.Context;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.TextView;public class MyAdapter extends BaseAdapter { List<Person> al = new ArrayList<Person>(); Context context; public MyAdapter(Context context) { super(); this.context = context; } public void addrest(List<Person> al) { this.al.clear(); this.al.addAll(al); this.notifyDataSetChanged(); } @Override public int getCount() { // TODO Auto-generated method stub return al.size(); } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = View.inflate(context, R.layout.items, null); TextView t = (TextView) view.findViewById(R.id.text); t.setText(al.get(position).name); return view; }}
values文件中 strings
<!--上拉刷新下拉加载控件的各个状态--> <string name="xlistview_header_hint_normal">下拉刷新</string> <string name="xlistview_header_hint_ready">松开刷新数据</string> <string name="xlistview_header_hint_loading">正在加载...</string> <string name="xlistview_header_last_time">上次更新时间:</string> <string name="xlistview_footer_hint_normal">查看更多</string> <string name="xlistview_footer_hint_ready">松开载入更多</string> <!--保存到本地的字段--> <string name="sp_name">egg_sp</string>
0 0
- XListView上拉刷新下拉加载(按两下能退出)
- XlistView上拉刷新下拉加载
- xListView上拉刷新下拉加载
- xListView上拉加载下拉刷新
- XListView上拉加载,下拉刷新
- xlistview上拉加载下拉刷新
- XListView上拉加载下拉刷新
- XListView上拉刷新,下拉加载
- 上拉刷新--下拉加载XListView
- XListView上拉加载下拉刷新
- xlistview上拉刷新、下拉加载
- XListView上拉加载下拉刷新
- XListView上拉加载下拉刷新
- XListView上拉加载下拉刷新
- Xlistview上拉加载下拉刷新
- xlistview上拉刷新,下拉加载
- 上拉刷新下拉加载xlistview-------string
- 上拉刷新下拉加载xlistview--------activity_main
- C#猜数字游戏
- 最新Linux版本 jira6.3.6安装汉化破解以及数据迁移
- 初识牛腩
- C++第6次实验-【项目3:矩阵求和】
- javascript语法之函数的定义
- XListView上拉刷新下拉加载(按两下能退出)
- CentOS7安装mysql-5.7(glibc版)
- poj 1088 滑雪
- SVN文件夹图标不正常显示解决方案
- iOS多线程的初步研究(九)-- dispatch源
- HIVE和HBASE区别
- Non Local Means-块匹配MATLAB和GPU实现
- MKL 进行矩阵向量运算
- PS基础——自由变换