首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用“加载更多结果”按钮的回收器视图

使用“加载更多结果”按钮的回收器视图
EN

Stack Overflow用户
提问于 2017-01-02 12:53:58
回答 3查看 2.2K关注 0票数 0

我需要一次在列表中显示10个元素。在加载10个元素后,用户将拥有“加载更多结果”按钮。单击此按钮,它将从服务器上再获取10个元素。如果一开始总没有。元素小于10,它不应该显示“加载更多的结果”按钮。

所以,我想用回收视图来开发这个,但是我不能这样做。请引导我。

提前谢谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-01-02 13:38:27

在您的xml中使loadButton可见性消失。

在活动类中,当您在API回调方法中将数据设置为适配器时,只需检查

代码语言:javascript
运行
复制
    if(list.size()>=10) {
    loadButton.setVisibility(VISIBLE);
    } else {
    loadButton.setVisibility(GONE);
    }
票数 1
EN

Stack Overflow用户

发布于 2017-01-02 13:58:49

你可以从这样的事情开始。

代码语言:javascript
运行
复制
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:nestedScrollingEnabled="false" />

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Load More"
                android:visibility="visible" />

        </LinearLayout>


    </android.support.v4.widget.NestedScrollView>

(实现逻辑取决于您;)

票数 1
EN

Stack Overflow用户

发布于 2017-01-02 13:19:06

RecyclerView.OnScrollListener

首先,在你的回收视图上实现OnScrollListener。您可以从滚动监听器中获取最后一项,并放置一个名为LOAD MORE的按钮。当你得到最后一项RecyclerView时,只需使其可见。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41427240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档