listView+SwipeRefreshLayout冲突

使用google推荐的下拉刷新,SwipeRefreshLayout刷新,listview下拉到最下面,无法回到第一条,默认下来刷新了

 

解决办法:listView.setOnScrollListener里面直接做判断

 

mAdapter = new MessageInfoAdapter(getContext(), mListDate, 1);
listView.setAdapter(mAdapter);
mAdapter.setListDataListener(listDataListener);

//设置颜色
refreshLayout.setColorSchemeColors(getResources().getColor(R.color.themeColor));
//刷新监听
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    @Override
    public void onRefresh() {
        mMessagePresenterImp.getData("untreated");  //刷新页面请求
    }
});

listView.setOnScrollListener(new AbsListView.OnScrollListener() {
    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        //判断ListView是否滑动到第一个Item的顶部
        if (refreshLayout != null && listView.getChildCount() > 0 && listView.getFirstVisiblePosition() == 0
                && listView.getChildAt(0).getTop() >= listView.getPaddingTop()) {
            //解决滑动冲突,当滑动到第一个item,下拉刷新才起作用
            refreshLayout.setEnabled(true);
        } else {
            refreshLayout.setEnabled(false);
        }
    }

    @Override
    public void onScroll(AbsListView absListView, int firstVisibleItem,
                         int visibleItemCount, int totalItemCount) {
    }
});

 

 

 

 

 

你可能感兴趣的:(android)