SwipeRefresh布局在sqlite

时间:2016-10-11 04:43:47

标签: android sqlite swiperefreshlayout

我正在使用刷卡刷新布局从本地sqlite加载数据我已将限制2和偏移量设置为0当列表刷新时数据未刷新我不知道为什么它不起作用任何人都可以帮助我重申这一点。

数据库:

 public ArrayList<TransactionSum> getAllTransactionList(int offset) {

    ArrayList<TransactionSum> transactionsum = new ArrayList<TransactionSum>();
    String selectquery = "SELECT tid,SUM(totalamount) as 'total',strftime('%m-%Y', tdate) as 'month' FROM " + TRANSACTION_LABELS + " WHERE tdate BETWEEN (select min(tdate) from transactionlabel) AND (select max(tdate) from transactionlabel) GROUP BY strftime('%m-%Y', tdate) ORDER BY strftime('%m-%Y', tdate) DESC LIMIT "+2+" OFFSET "+offset+" ";
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectquery, null);
    if (cursor.moveToFirst()) {
        do {
            TransactionSum transactiontotal = new TransactionSum();
            transactiontotal.setId(cursor.getString(0));
            transactiontotal.setTotalamount(cursor.getString(1));
            transactiontotal.setMonth(cursor.getString(2));

            transactionsum.add(transactiontotal);

        } while (cursor.moveToNext());

    }
    cursor.close();
    db.close();
    return transactionsum;
}

的活动:

 @Override
public void onRefresh() {
    fetchList();
}

private void fetchList() {
    swipeRefreshLayout.setRefreshing(true);


   databaseHandlerOtherChgs=new DatabaseHandlerOtherChgs(getApplicationContext());



    transactionitems=new ArrayList<TransactionSum>();
    transactionitems=databaseHandlerOtherChgs.getAllTransactionList(offSet);

       adapter = new TransactionListNewAdapter(this, transactionitems);
      for(int i=offSet;i<transactionitems.size();i++){
          offSet=offSet+i;
      }

        adapter.notifyDataSetChanged();



    swipeRefreshLayout.setRefreshing(false);
}

1 个答案:

答案 0 :(得分:0)

每次获取刷新列表时,您都在创建一个全新的适配器,但是您从不对此适配器执行任何操作。您必须在视图( let meal: MealCollectionViewController = (self.storyboard?.instantiateViewControllerWithIdentifier("STORYBIARD_CONTROLLER_IDEBTIFIER_NAME"))! as! MealCollectionViewController self.navigationController?.pushViewController(meal, animated: true) ,`RecyclerView&#39;上设置它,无论您使用哪个)。

或者,您可以向ListView添加一个方法,允许您更改其中的数据,并使用此方法而不是始终创建新的适配器。

TransactionListAdapter