带有“加载更多结果”按钮的回收站视图
我要求一次在列表中显示10个元素。加载10个元素后,用户将拥有“加载更多结果”按钮。点击这个按钮,它将从服务器获取另外10个元素。如果最初总数没有。的元素少于10,它不应该显示“加载更多结果”按钮。带有“加载更多结果”按钮的回收站视图
所以,我想开发这个使用Recycler View,但我无法做到这一点。 请指导我。
由于提前
在你的xml中使loadButton可见性消失。
在您的活动类,当你设置数据的API回调方法适配器,只需检查
if(list.size()>=10) {
loadButton.setVisibility(VISIBLE);
} else {
loadButton.setVisibility(GONE);
}
感谢变化回答 –
如果解决了问题,请将其标记为正确答案@AbdulRahaman –
首先实现你的recyclerview OnScrollListener
。您可以从滚动侦听器中获取最后一项,并放置一个名为LOAD MORE的按钮。当你得到RecyclerView
的最后一项时,使它可见。
感谢 –
谢谢@Vikas的 –
你可以像这样的东西开始。
<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>
实现逻辑给你;)
'“但我不能够做到这一点”'所以你尝试过这么远吗? – pskink
先加在数组列表10个项目,点击加载后更多结果增加10多个项目到数组列表,并做'adapter.notifyDataSetChanged()' – Redman
@Redman感谢您的建议 –