本文主要是介绍分批, 分页,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/*** 分页加载数据** @param pageNumber 表示当前是哪一页* @param pageSize 表示每一页有多少条数据* @return limit 表示限制当前有多少数据* offset 表示跳过 从第几条开始*/public List<BlackNumberInfo> findPar(int pageNumber, int pageSize) {SQLiteDatabase db = helper.getReadableDatabase();Cursor cursor = db.rawQuery("select number,mode from blacknumber limit ? offset ?", new String[]{String.valueOf(pageSize),String.valueOf(pageSize * pageNumber)});List<BlackNumberInfo> blackNumberInfos = new ArrayList<BlackNumberInfo>();while (cursor.moveToNext()) {BlackNumberInfo blackNumberInfo = new BlackNumberInfo();blackNumberInfo.setMode(cursor.getString(1));blackNumberInfo.setNumber(cursor.getString(0));blackNumberInfos.add(blackNumberInfo);}cursor.close();db.close();return blackNumberInfos;}
/*** 分批加载数据* @param startIndex 开始的位置* @param maxCount 每页展示的最大的条目* @return*/public List<BlackNumberInfo> findPar2(int startIndex, int maxCount) {SQLiteDatabase db = helper.getReadableDatabase();Cursor cursor = db.rawQuery("select number,mode from blacknumber limit ? offset ?", new String[]{String.valueOf(maxCount),String.valueOf(startIndex)});List<BlackNumberInfo> blackNumberInfos = new ArrayList<BlackNumberInfo>();while (cursor.moveToNext()) {BlackNumberInfo blackNumberInfo = new BlackNumberInfo();blackNumberInfo.setMode(cursor.getString(1));blackNumberInfo.setNumber(cursor.getString(0));blackNumberInfos.add(blackNumberInfo);}cursor.close();db.close();return blackNumberInfos;}
lv_call_sms_safe.setOnScrollListener(new OnScrollListener() {/*** 当滚动状态发生改变的时候调用这个方法* 静止--->滚动* 滚动--->静止* 手指触摸滑动--->惯性滚动*/@Overridepublic void onScrollStateChanged(AbsListView view, int scrollState) {switch (scrollState) {case OnScrollListener.SCROLL_STATE_IDLE://空闲状态int position = lv_call_sms_safe.getLastVisiblePosition();//19 最后一条显示的位置int total = list.size();//20总的数据有多少if(position == (total-1)){//最后一条了,该去加数据了Toast.makeText(getApplicationContext(), "加载更多数据", 0).show();}break;case OnScrollListener.SCROLL_STATE_FLING://惯性滑动break;case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL://触摸滚动default:break;}}/*** 当滚动的时候调用该方法*/@Overridepublic void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) {}});
这篇关于分批, 分页的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!