我需要一次在列表中显示10个元素。在加载10个元素后,用户将拥有“加载更多结果”按钮。单击此按钮,它将从服务器上再获取10个元素。如果一开始总没有。元素小于10,它不应该显示“加载更多的结果”按钮。
所以,我想用回收视图来开发这个,但是我不能这样做。请引导我。
提前谢谢
发布于 2017-01-02 13:38:27
在您的xml中使loadButton可见性消失。
在活动类中,当您在API回调方法中将数据设置为适配器时,只需检查
if(list.size()>=10) {
loadButton.setVisibility(VISIBLE);
} else {
loadButton.setVisibility(GONE);
}
发布于 2017-01-02 13:58:49
你可以从这样的事情开始。
<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>
(实现逻辑取决于您;)
发布于 2017-01-02 13:19:06
首先,在你的回收视图上实现OnScrollListener
。您可以从滚动监听器中获取最后一项,并放置一个名为LOAD MORE的按钮。当你得到最后一项RecyclerView
时,只需使其可见。
https://stackoverflow.com/questions/41427240
复制相似问题