安卓FragmentTabHost:没有标签闻名标签空 [英] Android FragmentTabHost : No tab known for tag null
本文介绍了安卓FragmentTabHost:没有标签闻名标签空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用低于code,它不渲染图形布局。显示误差异常渲染过程中提出的:没有标签出名的空标签
我该如何解决呢?
< android.support.v4.app.FragmentTabHost的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@机器人:ID / tabhost
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直>
< TabWidget
机器人:ID =@机器人:ID /标签
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =0
机器人:方向=横向/>
<的FrameLayout
机器人:ID =@机器人:ID / tabcontent
机器人:layout_width =0dp
机器人:layout_height =0dp
机器人:layout_weight =0/>
<的FrameLayout
机器人:ID =@ + ID / realtabcontent
机器人:layout_width =match_parent
机器人:layout_height =0dp
机器人:layout_weight =1/>
< / LinearLayout中>
< /android.support.v4.app.FragmentTabHost>
解决方案
这是我用来初始化TabHost的code和正常工作:
进口android.os.Bundle;
进口android.support.v4.app.Fragment;
进口android.support.v4.app.FragmentTabHost;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;
公共类DetailFragment扩展片段{
/ **
*必须填写空的构造的片段管理实例的片段(如在屏幕方向变化)。
* /
公共DetailFragment(){
}
@覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,捆绑savedInstanceState){
// R.layout.fragment_tabs_pager包含布局,在你的问题中指定
查看rootView = inflater.inflate(R.layout.fragment_tabs_pager,集装箱,假);
//初始化标签主机
FragmentTabHost mTabHost =(FragmentTabHost)rootView.findViewById(R.id.tabhost);
mTabHost.setup(getActivity(),getChildFragmentManager(),R.id.realtabcontent);
//初始化该列表某处与应该显示的内容
名单<字符串> itemsToBeDisplayed;
对于(字符串子项:itemsToBeDisplayed){
//给沿线的名字 - 你可以用它来交出例如一个ID
叠B =新包();
b.putString(TAB_ITEM_NAME,分项目);
//添加一个标签到tabHost
mTabHost.addTab(mTabHost.newTabSpec(分项).setIndicator(分项),YourContentFragment.class,B);
}
返回rootView;
}
}
/ **
*这个类包含一个标签的实际内容
* /
公共类YourContentFragment扩展片段{
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
捆绑额外= getArguments();
如果(临时演员!= NULL){
如果(extras.containsKey(TAB_ITEM_NAME)){
串子项= extras.getString(TAB_ITEM_NAME);
//做一些与该字符串
}
}
}
}
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 this ?
<android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<FrameLayout
android:id="@+id/realtabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
解决方案
This is the code that I've used to initialise the TabHost and it works fine:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class DetailFragment extends Fragment {
/**
* Mandatory empty constructor for the fragment manager to instantiate the fragment (e.g. upon screen orientation changes).
*/
public DetailFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// R.layout.fragment_tabs_pager contains the layout as specified in your question
View rootView = inflater.inflate(R.layout.fragment_tabs_pager, container, false);
// Initialise the tab-host
FragmentTabHost mTabHost = (FragmentTabHost) rootView.findViewById(R.id.tabhost);
mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);
// Initialise this list somewhere with the content that should be displayed
List<String> itemsToBeDisplayed;
for (String subItem : itemsToBeDisplayed) {
// Give along the name - you can use this to hand over an ID for example
Bundle b = new Bundle();
b.putString("TAB_ITEM_NAME", subItem);
// Add a tab to the tabHost
mTabHost.addTab(mTabHost.newTabSpec(subItem).setIndicator(subItem), YourContentFragment.class, b);
}
return rootView;
}
}
/**
* This class contains the actual content of a single tab
*/
public class YourContentFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getArguments();
if (extras != null) {
if (extras.containsKey("TAB_ITEM_NAME")) {
String subItem = extras.getString("TAB_ITEM_NAME");
// Do something with that string
}
}
}
}
这篇关于安卓FragmentTabHost:没有标签闻名标签空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文