LoadMoreList

Introduction: 赋予 ListView 加载更多能力的库
More: Author   ReportBugs   DemoAPK   
Tags:
Android-ListView-Java-加载更多--android-java-listview-

赋予 ListView 加载更多能力的库

示例图

使用方法

方法一:使用 LoadMoreListView

    //  如 demo 中的 MainActivity 所示代码
    //  注意 setFooterView 后才能 setAdapter,否则会出错
    mListView.setFooterView(View.inflate(this, R.layout.item_listview_footer_loadmore, null), new OnLoadMoreScrollListener.OnLoadMoreStateListener() {
                @Override
                public void onNormal(View footView) {
                    footView.findViewById(R.id.footer_pb_loading).setVisibility(View.GONE);
                    ((TextView) footView.findViewById(R.id.footer_tv_msg)).setText("加载更多");
                }

                @Override
                public void onLoading(View footView) {
                    footView.findViewById(R.id.footer_pb_loading).setVisibility(View.VISIBLE);
                    ((TextView) footView.findViewById(R.id.footer_tv_msg)).setText("正在加载...");

                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            SystemClock.sleep(2000);
                            loadMore();
                        }
                    }).start();
                }

                @Override
                public void onEnd(View footView) {
                    footView.findViewById(R.id.footer_pb_loading).setVisibility(View.GONE);
                    ((TextView) footView.findViewById(R.id.footer_tv_msg)).setText("已加载全部");
                }
            });
            mAdapter = new ArrayAdapter<>(getBaseContext(), android.R.layout.simple_expandable_list_item_1, mList);
            mListView.setAdapter(mAdapter);

方法二:使用 OnLoadMoreScrollLister

    // 如库中 LoadMoreListView 所示代码
    // 先 new OnLoadMoreScrollListenr 后才 setAdapter,否则会出错
    OnLoadMoreScrollListener mScrollListener = new OnLoadMoreScrollListener(mListView, footerView);
    mListView.setOnScrollListener(mScrollListener);
    mScrollListener.setOnLoadMoreStateListener(new OnLoadMoreScrollListener.OnLoadMoreStateListener() {
        ......
    });
Android 开发经验分享
随手点击下面广告支持本站吧
 
Android 开发经验分享