java - 对 android 中的两个选项卡使用相同的 RecyclerView
问题描述
我的. RecyclerView
_ 当每个选项卡被选中时,我只想在 RecyclerView 中显示另一个数据。为此,我应该使用 ViewPager for Tabs 吗?我应该使用片段吗?我真的不知道。我的示例中需要它们吗?选项卡之间的唯一区别只是它们在 RecylerView 中向用户显示的数据。是一样的。是一样的,等等。有人可以帮助我吗?谢谢Tab
MainActivity
RecyerView
Toolbar
解决方案
First off yes you will need a ViewPager
. This ViewPager
will require you to use Fragments
. Take a look at this example from the official docs.
To solve your RecyclerView
problem you have two options:
- define a custom
RecyclerView
(by extending Androids RecyclerView) - defining a custom
RecyclerViewAdapter
and use it with aRecyclerView
I would advise you to do the first if the RecyclerViews are completely similar. Then you could define all your properties with it, without having to do that twice in your Tab Fragment. Otherwise take the second option.
推荐阅读
- javascript - Ngx引导日期选择器的最大类型数?
- sql - 从字符串转换日期和/或时间时出现转换失败错误
- python - 求解具有巨大矩阵的线性方程组的最快方法
- macos - 在 MacOS 上无法 ssh 到 22 以外的本地主机端口
- python - 单元格中具有多个值的表格的计数/透视
- python - 使用 Python 从 JSON 文件中选择数据
- javascript - 用于工作表的 Google 脚本不复制单元格内的公式,仅复制值
- c# - Selenium-Nunit 如何等待几个图像
- sparql - 元素转换 Apache Jena
- javascript - 如何导入自定义 ES6 模块?