Chanven / CommonPullToRefresh

Android widget with pull to refresh for all the views,and support loadMore for ListView , RecyclerView, GridView and SwipeRefreshLayout.
Apache License 2.0
1.07k stars 303 forks source link

Demo:ListView当footView出现一点就开始加载更多,而RecyclerView需要footView全部出现才可以加载更多? #47

Closed s1168805219 closed 8 years ago

s1168805219 commented 8 years ago

我在运行Demo的时候发现2个问题:都是上拉加载更多 第一个: 若是ListView,那么当footView出现一点点的时候就会加载更多,而RecyclerView需要footView全部出现才会加载更多。 第二个: mData.add(new String(" RecyclerView item - add " + page)); mAdapter.notifyDataSetChanged(); 必须在一起,如果采用mHandler.sendEmptyMessageDelayed(123, 1500);把加载数据和 mAdapter.notifyDataSetChanged();分开,会有bug。

    ptrClassicFrameLayout.setPtrHandler(new PtrDefaultHandler() {

        @Override
        public void onRefreshBegin(PtrFrameLayout frame) {
                 mData.add(new String("  RecyclerView item  - add " + page));
                mHandler.sendEmptyMessageDelayed(123, 1500);
        }
    });

private Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        if (msg.what == 123) {
            mAdapter.notifyDataSetChanged();
            ptrClassicFrameLayout.loadMoreComplete(true);
            page++;
            Toast.makeText(RecyclerViewActivity.this, "load more complete", Toast.LENGTH_SHORT).show();
        }
    }
};

会出现bug:一次正常有1.5s的间隔,一次没有(直接是加载更多后的结果),依次循环。

Chanven commented 8 years ago

1.listview使用getLastVisiblePosition()方法判断是否到底部的,所以只要可见就会开始加载。 2.看代码,你把Handler发消息写在下拉刷新的接口里。。。

s1168805219 commented 8 years ago

多谢