Android_自己写的简单上拉加载
来源:互联网 发布:淘宝买的鲜人参怎么样 编辑:程序博客网 时间:2024/06/03 15:02
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ListView android:id="@+id/listView_listView1" android:layout_width="match_parent" android:layout_height="match_parent" /></LinearLayout>
footer.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ProgressBar android:id="@+id/progressBar1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/progressBar1" android:layout_marginTop="10dp" android:text="加载中......" android:textAppearance="?android:attr/textAppearanceLarge" /></RelativeLayout>
Activity
package com.lxf;import java.util.ArrayList;import java.util.List;import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.os.SystemClock;import android.view.View;import android.widget.AbsListView;import android.widget.AbsListView.OnScrollListener;import android.widget.ArrayAdapter;import android.widget.ListView;import android.widget.Toast;/** * @address BeiJing * @author LiXufei * @function android_listview */public class cListView extends Activity{ private ListView view1; private List<String> list = new ArrayList<String>(); private ArrayAdapter<String> adapter; private final int SUCCESS = 0; //加载成功标志 private boolean flag = true; //是否刷新 private View footerView; //页脚 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.android_listview); view1 = (ListView) findViewById(R.id.listView_listView1); //初始化页脚 footerView = getLayoutInflater().inflate(R.layout.android_listview_footer,null ); //初始化数据 list.addAll(addData(20)); //初始化适配器 adapter = new ArrayAdapter<String>(cListView.this, android.R.layout.simple_list_item_1, list); //适配器 view1.setAdapter(adapter); //设置滚动监听 view1.setOnScrollListener(new MyScrollListner(5, 20)); } //handler private Handler handler = new Handler(){ public void handleMessage(android.os.Message msg) { if (msg.what == SUCCESS) { flag = true; List<String>res = (List<String>) msg.obj ; list.addAll(res); adapter.notifyDataSetChanged(); Toast.makeText(cListView.this, "加载成功!", 0).show(); } if (flag) { if (view1.getFooterViewsCount() > 0) { view1.removeFooterView(footerView); } } }; }; //滚动刷新类 class MyScrollListner implements OnScrollListener{ private int pageCount; //加载的页数 private int pageSize; //加载的个数 public MyScrollListner(int countPage, int sizePage) { super(); this.pageCount = countPage; this.pageSize = sizePage; } public void onScrollStateChanged(AbsListView view, int scrollState) { } public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { int currentCount = firstVisibleItem+visibleItemCount; //当前个数 int currentPage = currentCount/pageSize; //当前的页数 int nextPage = currentPage+1; //下个页数 if (currentCount == totalItemCount && nextPage <= pageCount && flag) { //执行数据刷新 view1.addFooterView(footerView); //添加页脚 flag = false; //改变标志 new Thread(){ public void run() { SystemClock.sleep(3000);//睡眠3秒,不会立即加载 List<String> addData = addData(pageSize); //获取新数据 //通过handler更新listview Message message = Message.obtain(); message.what = SUCCESS; message.obj = addData; handler.sendMessage(message); }; }.start(); } } } //添加数据方法 public List<String> addData(int Count){ ArrayList<String> datas = new ArrayList<String>(); //准备数据 for (int i = 0; i <= Count; i++) { datas.add("数据"+i); } return datas; }}
1 0
- Android_自己写的简单上拉加载
- 基于vue2写的上拉加载
- 基于vue2写的上拉加载
- android 简单的上拉加载实现
- 简单的ListView上拉加载
- 简单实现上拉加载的RecyclerView
- RecyclerView 上拉加载的简单封装
- Android_下拉刷新上拉加载_FloatMath.floor()不能用
- 一步一步封装自己的Recycleview,上拉加载
- 一步步打造自己的通用上拉加载布局
- 自个儿写Android的下拉刷新/上拉加载控件
- Android的ListView简单的自定义上拉加载
- android下拉刷新上拉加载简单的实现方法;
- RecyclerView的简单使用,实现下拉刷新、上拉加载
- RecyclerView 最简单的 下拉刷新 上拉加载
- JAVASCRIPT超级简单的上拉刷新下拉加载
- 简单好用的上拉加载下拉刷新 BaseRecyclerViewAdapterHelper
- 简单的上拉加载下拉刷新实现
- 断网联网或者是解锁完成的广播
- CcentOS 安装VMware Tools 命令
- QT5.6.0安装错误记录
- yii2框架-yii2的rules验证(七)
- php基础知识笔记 一
- Android_自己写的简单上拉加载
- Assets文件夹
- 你想跳槽,五个错不要犯!
- C#学习笔记集合类型之数组(3)
- MySQL的grant,revoke使用
- ACM3-1007
- PID12 / 陶陶摘苹果 ☆
- java static
- CSS特效代码整理