如何实现onResume()的无限滚动?

时间:2015-05-15 11:52:24

标签: android

我如何实现onResume()的无限滚动,当前onCreateView,我实现了一个无限的Scroll,它工作得很好但是当它涉及onResume()时,它不会在另一个工作中显示空白数据

这里是onCreate的代码

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        onRestoreInstanceState(savedInstanceState);
        View rootView = inflater.inflate(com.barakah.camel.R.layout.browse_fragment_layout,
                container, false);
        setupFloatingActionMenu(getActivity());
        recyclerView = (RecyclerView) rootView
                .findViewById(com.barakah.camel.R.id.my_recycler_view);
        layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);

        recyclerView.setOnScrollListener(new EndlessRecyclerOnScrollListener(
                layoutManager) {
            @Override
            public void onLoadMore(int current_page) {
                int limit = current_page * 5;
                LoadMoreItems(limit);
            }
        });
        return rootView;
    }

这里是onResume()

的代码
public View onResume(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        onRestoreInstanceState(savedInstanceState);
        super.onResume();
        View rootView = inflater.inflate(com.barakah.camel.R.layout.browse_fragment_layout,
                container, false);
        setupFloatingActionMenu(getActivity());
        recyclerView = (RecyclerView) rootView
                .findViewById(com.barakah.camel.R.id.my_recycler_view);
        layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);

        recyclerView.setOnScrollListener(new EndlessRecyclerOnScrollListener(
                layoutManager) {
            @Override
            public void onLoadMore(int current_page) {
                int limit = current_page * 5;
                LoadMoreItems(limit);
            }
        });
        return rootView;
    }

任何帮助都会得到应用

1 个答案:

答案 0 :(得分:1)

您的onResume()方法未正确覆盖ActivityFragment中找到的同名方法。

该方法不应返回View,因为它是void方法。 喜欢之类的东西可能就是你所追求的:

即:

@Override
public void onResume() {
    super.onResume();
    recyclerView.setOnScrollListener(new EndlessRecyclerOnScrollListener(layoutManager) {
        @Override
        public void onLoadMore(int current_page) {
            int limit = current_page * 5;
            LoadMoreItems(limit);
        }
    });
}