简体   繁体   English

Android Studio:强制选项卡呈现

[英]Android Studio: Force tab to render

So I have an application with 3 tabs.所以我有一个带有 3 个选项卡的应用程序。 The thing is, when I pull one of the tabs up, I want the other two to render and never have to re-render while on these tabs.问题是,当我拉起其中一个选项卡时,我希望其他两个进行渲染,而不必在这些选项卡上重新渲染。

In other words, clicking on any of these tabs will not cause onCreateView to be called again.换句话说,单击这些选项卡中的任何一个都不会导致再次调用 onCreateView。 Here is my pager adapter:这是我的寻呼机适配器:

            return when (position) {
                0 -> {
                    ProfilePageFragment()
                }
                1 -> {
                    SwipeFragment()
                }
                2 -> {
                    MessagesFragment()
                }
                else -> {
                    MessagesFragment()
                }

When I click on tab0, tab1 is rendered, and when I click on tab1, tab2 is rendered.当我点击 tab0 时,tab1 被渲染,当我点击 tab1 时,tab2 被渲染。 It seems I leave the rendering when I go 2 tabs in a certain direction, in which going back will cause a re render.当我朝某个方向移动 2 个选项卡时,我似乎离开了渲染,返回将导致重新渲染。 (Please let me know if that didn't make sense) (如果这没有意义,请告诉我)

How do I get rid of this, or increase this number so that the re-rendering doesn't happen with 3 tabs?我如何摆脱这个,或增加这个数字,以便重新渲染不会发生在 3 个选项卡上? I would assume it is one of the @override methods in the PagerAdapter.我认为它是 PagerAdapter 中的 @override 方法之一。 Thank you.谢谢你。

Found the answer.找到了答案。 Much more simple than I thought.比我想象的要简单得多。 Just return on the destroy method:只需返回 destroy 方法:


    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        return
    }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM