首页 > 解决方案 > 对 android 中的两个选项卡使用相同的 RecyclerView

问题描述

我的. RecyclerView_ 当每个选项卡被选中时,我只想在 RecyclerView 中显示另一个数据。为此,我应该使用 ViewPager for Tabs 吗?我应该使用片段吗?我真的不知道。我的示例中需要它们吗?选项卡之间的唯一区别只是它们在 RecylerView 中向用户显示的数据。是一样的。是一样的,等等。有人可以帮助我吗?谢谢TabMainActivityRecyerViewToolbar

标签: javaandroidandroid-viewpagerfragmenttoolbar

解决方案


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 a RecyclerView

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.


推荐阅读