代码之家  ›  专栏  ›  技术社区  ›  Abner Escócio

方法removeAllTabs()从Tablayout中无效

  •  0
  • Abner Escócio  · 技术社区  · 8 年前

    我面临着这个问题:每次我从Tablayout的标签都不会被删除

    我在里面添加标签 onCreateView 把它们移到里面去 onDetach

    但当我回到这里 fragment ,我的标签继续 tabLayout

    class ProductsFragment : Fragment(), TabLayout.OnTabSelectedListener {
    
        private var tabLayout: TabLayout? = null
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            ...
            tabLayout = activity!!.findViewById(R.id.tablayout)
            ...
        }
    
        ...
    
        override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
            //here I'm adding the tabs to tabLayout
        }
    
        ...
    
        override fun onDetach() {
            super.onDetach()
            tabLayout?.removeAllTabs()
        }
    }
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Tim Abhishek Kumar    8 年前

    onDetach 在视图已被销毁后调用。你的推荐信 tabLayout onDestroyView 或者类似的。