刷卡刷新后Recycleview显示错误数据

时间:2019-02-18 16:56:14

标签: java android android-recyclerview

我已经实现了带有刷卡刷新的RecyclerView。刷卡后,我通过调用API刷新数据。但是RecyclerView总是显示错误的数据,并且与被调用的API有所不同(例如重复/错误的位置)

我在此适配器上添加此代码时得到了答案,但无济于事。我做错了什么?

@Override
public int getItemViewType(int position)
{
    return position;
}

我的片段

@Override
public void onResume() {
    super.onResume();
    if (allowRefresh)
    {
        allowRefresh = false;
        getFragmentManager().beginTransaction().detach(this).attach(this).commit();
    }
}

@Override
public void onRefresh() {
    loadRecyclerViewData();

}

public void loadRecyclerViewData(){
//some code
  @Override
  public void accept (List<UnpaidOrder> unpaidOrders) throws Exception
  {
    Log.d("Unpaid Order Fragment", "accept: Data Refreshed");
    mUnpaidOrder.clear();
    mUnpaidOrder.addAll(unpaidOrders);
    mBinding.rvUnpaidOrder.getAdapter().notifyDataSetChanged();
    if (mUnpaidOrder.size() == 0)
    {
      mBinding.llUnpaidList.showEmptyView(true);
    }
    mBinding.swipeUnpaidOrder.setRefreshing(false);
  }
  //some code

0 个答案:

没有答案