[CymChad/BaseRecyclerViewAdapterHelper]关于局部刷新的问题

2024-08-08 224 views
8

我想问下,我在Adapter里做了单个控件的点击事件,然后要求局部刷新一下,这个要怎么实现啊

回答

0
// 数据发生了改变,那调用这个方法,传入改变对象的位置。
public final void notifyItemChanged(int position);
7

是在convert方法中使用么

7

麻烦可以问下,分页加载数据的时候要怎么做呢,可以给我份代码看看嘛?

1

@BugMen demo和wiki都有代码

8

上拉加载

4

不是,我的意思是,DEMO里的数据好像是一次性拿到所有,然后去做分页,但是如果是一开始从网络上拿数据的时候就做分页处理呢,这个也是和Demo上的处理方式一样么?

6

恩 是的 一样的。

8

那addData()这个方法里传的值就是网络数据请求的所有数据么?

2

恩 是的,写在成功的回调里面即可

8

好的,我再试下,谢谢咯!

4

你好! public class TestClass extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener {

@ViewInject(id = R.id.swiperefreshlayout)
private SwipeRefreshLayout swipeRefreshLayout;
@ViewInject(id = R.id.recyclerview)
private RecyclerView recyclerView;

private List<HomePagePlanModel> homePagePlanList = new ArrayList<HomePagePlanModel>();
private HomePagePlanAdapter homePagePlanAdapter;

private int skip = 0;
private int take = AppSetting.MiddlePageSize;

private int TOTAL_COUNTER = 0;

private int mCurrentCounter = 0;

private boolean isErr;

private int sortType = 0; // 排序方式:默认 0、发布时间排序,1、中奖SP大小排序
private int notFree = 0; // 收费方案:默认 0、查询所有,1、收费方案
private int matchType = 0; // 赛事类型:默认 0、查询所有,1、竞彩,2、北单,3、足彩14场,4、任九
private int madeNotes = 0; // 笔记方案:默认 0、查询所有,1、只看笔记方案
private int realPlan = 0; // 实单方案:默认 0、查询所有,1、只看实单方案

private boolean mLoadMoreEndGone = false;
View notDataView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test);

    notDataView = getLayoutInflater().inflate(R.layout.layout_nodata, (ViewGroup) recyclerView.getParent(), false);

    initRecyclerView(recyclerView);

    initSwipeRefreshLayout(swipeRefreshLayout);

    loadPlanList(10143, sortType, notFree, matchType, madeNotes, realPlan);

    initAdapter();
}

/**
 * 初始化RecyclerView
 *
 * @param recyclerView
 */
private void initRecyclerView(RecyclerView recyclerView) {
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));
}

private void initSwipeRefreshLayout(final SwipeRefreshLayout swipeRefreshLayout) {

// swipeRefreshLayout.post(new Runnable() { // @Override // public void run() { // swipeRefreshLayout.setRefreshing(true); // loadPlanList(10143, sortType, notFree, matchType, madeNotes, realPlan); // initAdapter(); // } // }); swipeRefreshLayout.setOnRefreshListener(this); }

private void initAdapter() {
    homePagePlanAdapter = new HomePagePlanAdapter(homePagePlanList, 10143);
    homePagePlanAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
    recyclerView.setAdapter(homePagePlanAdapter);
    homePagePlanAdapter.setEmptyView(notDataView);
    mCurrentCounter = homePagePlanAdapter.getData().size();
    recyclerView.addOnItemTouchListener(new OnItemClickListener() {
        @Override
        public void onSimpleItemClick(final BaseQuickAdapter adapter, final View view, final int position) {
            Toast.makeText(TestClass.this, Integer.toString(position), Toast.LENGTH_LONG).show();
        }
    });
}

private void loadPlanList(final int membershipId, int sorttype, int notfree, int matchtype, int madeNotes, final int realPlan) {
    OXPlanBLL.Instance().getMainHomePlan(membershipId, skip, take, sorttype, notfree, matchtype, madeNotes, realPlan, this, new DataCallBack<Result<List<HomePagePlanModel>>>() {
        @Override
        public void onSuccess(final Result<List<HomePagePlanModel>> homePagePlanModels) {
            if (homePagePlanModels.JsonData != null) {
                homePagePlanList.clear();
                homePagePlanList.addAll(homePagePlanModels.JsonData);
                homePagePlanAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
                    @Override
                    public void onLoadMoreRequested() {
                        swipeRefreshLayout.setEnabled(false);
                        recyclerView.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                if (homePagePlanAdapter.getData().size() < PAGE_SIZE) {
                                    homePagePlanAdapter.loadMoreEnd(true);
                                } else {
                                    if (mCurrentCounter >= TOTAL_COUNTER) {
                                        homePagePlanAdapter.loadMoreEnd(mLoadMoreEndGone);//true is gone,false is visible
                                    } else {
                                        if (isErr) {
                                            homePagePlanAdapter.addData(homePagePlanList);
                                            mCurrentCounter = homePagePlanAdapter.getData().size();
                                            homePagePlanAdapter.loadMoreComplete();
                                        } else {
                                            isErr = true;
                                            Toast.makeText(TestClass.this, "加载失败", Toast.LENGTH_LONG).show();
                                            homePagePlanAdapter.loadMoreFail();

                                        }
                                    }
                                    swipeRefreshLayout.setEnabled(true);
                                }
                            }

                        }, 1);
                    }
                });
            }
            swipeRefreshLayout.setRefreshing(false);
        }

        @Override
        public void onError(Context context, String errorCode, String title, String message) {
            super.onError(context, errorCode, title, message);
        }
    });
}

@Override
public void onRefresh() {
    homePagePlanAdapter.setEnableLoadMore(false);
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            homePagePlanAdapter.setNewData(homePagePlanList);
            isErr = false;
            mCurrentCounter = PAGE_SIZE;
            swipeRefreshLayout.setRefreshing(false);
            homePagePlanAdapter.setEnableLoadMore(true);
        }
    }, 1);
}

} 这是我写的分页加载网络数据的方法,但是有问题,我是按照Demo的写法写的,所以麻烦帮我看下在自动加载那里出了什么问题啊

3

从新开个issues,并且附上版本号,代码使用代码块包裹,还有xml布局代码。谢谢这样便于我们更快定位问题。