简体   繁体   English

在recyclerview之间切换或切换内容

[英]Switching between recyclerview or switching content

In my application, I have multiple dynamic lists in which the user can navigate between them. 在我的应用程序中,我有多个动态列表,用户可以在其中进行导航。 For simplification, the app has a main screen which shows a list of items. 为简化起见,该应用程序有一个主屏幕,其中显示项目列表。 When the user clicks on any of the items, a new list should be shown, and again if he/she clicks on an item again, a new list should be shown. 当用户单击任何一个项目时,应该显示一个新列表,并且如果他/她再次单击一个项目,则应该显示一个新列表。 Moreover, the user should have the ability to navigate back to the previous screen. 此外,用户应具有导航回到上一个屏幕的能力。

I considered two options for implementing this: 我考虑了实现此目的的两种选择:

  1. Using the same recyclerview and change the content when needed. 使用相同的recyclerview,并在需要时更改内容。

  2. Using fragment with recyclerview and replace the fragment with a new fragment that shown a recyclerview with the new content. 将片段与recyclerview一起使用,并用显示新内容的recyclerview的新片段替换片段。

My question is about the implications of each of these implementations, especially in term of efficiency and user experience, or if someone can suggest a better approach to this situation. 我的问题是关于每种实现的含义,特别是在效率和用户体验方面,或者是否有人可以针对这种情况提出更好的方法。 I know a little about fragments and recyclerview, and I think that using fragment might be preferable since it is suitable if I ever plan to make the application fit into tablets and devices with a bigger screen. 我对碎片和recyclerview有所了解,我认为使用碎片可能会更可取,因为如果我计划使应用程序适合具有更大屏幕的平板电脑和设备,则使用碎片是合适的。 I planned to test both to understand them better. 我计划测试两者以更好地理解它们。 However, I still hoped to hear more opinions. 但是,我仍然希望听到更多的意见。

I would like to thanks in advance to anyone who will share his opinion with me. 在此先感谢与我分享他的观点的任何人。

我认为使用带有recyclerview的片段并将片段替换为显示具有新内容的recyclerview的新片段是首选,因为如果您需要对UI进行一些更改,那么片段将是不错的选择。

I will suggest you use fragments for this implementation. 我建议您使用片段进行此实现。 So that you don't write huge lines file in one class. 这样一来,您就不会在一个类中编写大型行文件。

Also it will reduce future problems if app will upgrade and UI or functionality changes, then you will have separate code to change. 此外,如果应用程序将升级并且UI或功能发生更改,它将减少将来的问题,那么您将需要更改单独的代码。

Keeping adapters and fragments separate will lead more efficient way to manage user interactions. 将适配器和片段分开将导致更有效的方式来管理用户交互。

Also you don't need to maintain views stack, android will take care of backpress itself. 另外,您不需要维护视图堆栈,Android会自行处理backpress。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在包含RecyclerView的片段之间切换时出现NullPointerException - NullPointerException when switching between fragments containing RecyclerView 在为单个 recyclerview 使用多个适配器之间切换 - Switching between using multiple adapters for a single recyclerview RecyclerView动画,同时切换瓷砖和网格 - RecyclerView Animations while switching between tiles and grid 在片段之间切换后,RecyclerView项目消失 - RecyclerView items disappear after switching between fragments 在布局之间切换并保持内容显示 - Switching between layouts and keeping content displayed 在RecyclerView中切换项目视图类型 - Switching item viewtypes in RecyclerView RecyclerView 在特定 Activity 的片段之间切换后消失 - RecyclerView disappearing after switching between fragments on a particular Activity 切换到Activity1(RecyclerView)切换到Activity2(RecyclerView) - Switching to Activity1 (RecyclerView) to Activity2 (RecyclerView) 计算打开和关闭之间的时间 - Calculate time between switching on and switching off 在ListView和GridView之间切换内容视图时,对项目进行动画过渡 - Animate transition of items when switching content view between ListView and GridView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM