[英]Putting ViewPager and tabs in a fragment and replacing it
In my main activity I have a ViewPager
with two tabs and each of them has its contents in a fragment. 在我的主要活动中,我有一个带有两个选项卡的
ViewPager
,每个选项卡的内容都在一个片段中。 One of the tabs holds a list of items and when I press on an item from that list I want the details of that item to appear on the screen. 选项卡中的一个包含项目列表,当我按该列表中的项目时,我希望该项目的详细信息显示在屏幕上。 I thought of putting the whole
ViewPager
in a fragment and when the user taps the item the fragment representing the whole ViewPager
is replaced with another fragment representing the details of the item. 我想将整个
ViewPager
放在一个片段中,当用户点击该项目时,代表整个ViewPager
的片段将被替换为另一个代表该项目详细信息的片段。 Is it possible and is it a good practice? 有可能吗,这是一个好习惯吗? Maybe I should just start another activity with the details of the item?
也许我应该就该项目的细节开始另一项活动?
How you do it is your own choice. 您如何选择是您自己的选择。 It's perfectly fine to switch your Fragments.
切换片段非常好。
getSupportFragmentManager().beginTransaction().replace(android.R.id.content, new FragDetails())
.addToBackStack(FragPager.class.getName()).commit();
Switching to another Activity is fine too, you just have more of a "flicking" screen when opening a new Activity (and some other life cycle stuff too of course). 切换到另一个Activity也很好,当打开一个新的Activity时,您只是拥有更多的“轻拂”屏幕(当然,还有其他一些生命周期的东西)。 If you don't want that, switch Fragments.
如果您不想这样做,请切换“片段”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.