Android FragmentTabHost : No tab known for tag null

前端 未结 7 473
悲&欢浪女
悲&欢浪女 2020-12-09 01:16

I used below code and it is not render graphical layout. display error as Exception raised during rendering: No tab known for tag null.

how can i solve

7条回答
  •  一个人的身影
    2020-12-09 01:38

    I got a similar problem on using tabHost in fragments, searched a lot and finally found a solution to that.

    1) Keep you code in on create view

    2) This is the key -> While inflating the layout for tab indicators use as follows

    View tabIndicator = LayoutInflater.from(getActivity()).inflate(R.layout.tab_indicator, mTabHost.getTabWidget(), false);
    

    We need to set the parent value in the inflater as mTabHost.getTabWidget()

    Setting tab indicator using the above code solved the issue of

              Java : illegal state exception : no tab know for tag null
    

    Update :

    mTabHost = (FragmentTabHost) view.findViewById(android.R.id.tabhost);
    
    mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
    
    View tabIndicatorToday = LayoutInflater.from(getActivity()).inflate(R.layout.tab_indicator, mTabHost.getTabWidget(), false);
            ((TextView) tabIndicatorToday.findViewById(R.id.tv_tab_txt)).setText(getResources().getString(R.string.text));
    
    mTabHost.addTab(mTabHost.newTabSpec(getResources().getString(R.string.text)).setIndicator(tabIndicatorToday), Fragment.class, null);
    

提交回复
热议问题