5.2 分页显示

    /*    Fields  */
       private   int   pageSize   = 10;    
       private   int   currentPage   = 1;
       private   int   maxPage ;
       private   int   countRows ;


------------------------------------------------------------------------



 
       /**
       * 查询所有黑名单个数
       *   @return
       */
       public   int   getMaxNumber(){
               int   total=0;
            SQLiteDatabase db =   helper .getWritableDatabase();
            Cursor cursor = db.rawQuery(   "select * from blacknumber" ,   null );
            total=cursor.getCount();    //得到数据库有多少条记录
          db.close();
               return   total;
      }
      
      
      
       /**
       * 获取一共有多少页的内容.
       *   @param   pageSize
       *   @return
       */
       public   int   getTotalPage(   int   pageSize){
               int   total = getMaxNumber();
               if (total%pageSize ==0){
                     return   total/pageSize;
            }   else {
                     return   total/pageSize+1;
            }
      }
      
       /**
       * 分页的获取黑名单号码
       * currentPage   当前第几页
      * PageSize     每页显示多少条数据
       *   @return
       */
public   List<BlackNumberBean>   getBlackNumberInfosByPage( int   currentPage, int   PageSize){
            
               try   {
                  Thread. sleep(600); 
            }   catch   (InterruptedException e) {
                  e.printStackTrace();
            }
            
            List<BlackNumberBean>  numberList=   new   ArrayList<BlackNumberBean>();
            SQLiteDatabase db =   helper .getWritableDatabase();
      
            Cursor cursor = db.rawQuery(   "select * from blacknumber  limit ? , ?" ,   new   String[] {
                        String. valueOf(currentPage), String.valueOf((currentPage-1)*PageSize) });
            
               while (cursor.moveToNext()){
                  BlackNumberBean  numberBean=   new   BlackNumberBean();
                  numberBean.setId(cursor.getInt(cursor.getColumnIndex(   "id" )));
                  numberBean.setNumber(cursor.getString(cursor.getColumnIndex(   "number" )));
                  numberBean.setMode(cursor.getString(cursor.getColumnIndex(   "mode" )));
                  
                  numberList.add(numberBean);
                  
            }
          db.close();
               return   numberList;
      }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值