Android &引用;找不到id“的视图”;在TabHost设置中选择容器

Android &引用;找不到id“的视图”;在TabHost设置中选择容器,android,fragment,android-tabhost,android-alertdialog,Android,Fragment,Android Tabhost,Android Alertdialog,我正在创建一个对话框,其中有x个选项卡,用户可以从中进行选择。这种情况的独特之处在于,我的活动已经有了一个TabHost。不知怎么的,TabHost工作正常,但我的新主机不工作。我得到的错误是: java.lang.IllegalArgumentException: No view found for id 0x7f0b005c (nl.raakict.android.spc:id/realtabcontent2) for fragment CreateCarrierTabFragment{21

我正在创建一个对话框,其中有x个选项卡,用户可以从中进行选择。这种情况的独特之处在于,我的活动已经有了一个TabHost。不知怎么的,TabHost工作正常,但我的新主机不工作。我得到的错误是:

java.lang.IllegalArgumentException: No view found for id 0x7f0b005c (nl.raakict.android.spc:id/realtabcontent2) for fragment CreateCarrierTabFragment{211feed8 #2 id=0x7f0b005c Overig} 
但我确信视图id是存在的,因为这是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <android.support.v4.app.FragmentTabHost
        android:id="@+id/tabhost2"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
            <TabWidget
                android:id="@+id/tabs2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent" />
            <FrameLayout
                android:id="@+id/realtabcontent2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </android.support.v4.app.FragmentTabHost>
</LinearLayout>

这是我在调试模式下看到的,如果我在id上执行findviewbyid:

我的全班代码:

package nl.raakict.android.spc.Fragment;

import android.app.AlertDialog;
import android.app.Dialog;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

import nl.raakict.android.spc.Controller.API;
import nl.raakict.android.spc.Model.CarrierCategory;
import nl.raakict.android.spc.Model.CarrierType;
import nl.raakict.android.spc.R;

public class PopupCreateCarrier extends DialogFragment {

    private FragmentTabHost mTabHost;
    private API mApi;
    private ArrayList<CarrierType> carrierTypes;
    private HashMap<Long, CarrierCategory> carrierCategories;
    private HashMap<Long, View> carrierCategoriesViewIndicators;
    private HashMap<Long, ArrayList<CarrierType>> indicatorCarrierTypes;
    private LayoutInflater layoutInflater;
    private CarrierCategory otherCategory;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        layoutInflater = LayoutInflater.from(getActivity());
//        final View view = layoutInflater.inflate(R.layout.fragment_tab_host_new_carrier, null);
//        indicatorCarrierTypes = new HashMap<Long, ArrayList<CarrierType>>();
//        mApi = API.getInstance(getActivity());
//        mApi.GetCarrierCategories(this);
//        mTabHost = (FragmentTabHost) view.findViewById(android.R.id.tabhost);
//        mTabHost.setup(getActivity(), getActivity().getSupportFragmentManager(), R.id.realtabcontent);
//        otherCategory = new CarrierCategory();
//        otherCategory.setName("Overig");
//        otherCategory.setID(Long.MAX_VALUE);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        layoutInflater = LayoutInflater.from(getActivity());
        final View view = layoutInflater.inflate(R.layout.fragment_tab_host_new_carrier, null);
        otherCategory = new CarrierCategory();
        otherCategory.setName("Overig");
        otherCategory.setID(Long.MAX_VALUE);
        indicatorCarrierTypes = new HashMap<Long, ArrayList<CarrierType>>();
        mApi = API.getInstance(getActivity());
        mTabHost = (FragmentTabHost) view.findViewById(R.id.tabhost2);
        View test = view.findViewById(R.id.realtabcontent2);
        mTabHost.setup(getActivity(), getActivity().getSupportFragmentManager(), R.id.realtabcontent2);

        mapCategoriesToHashMaps();
        mapCarrierTypesToHashMaps();
        setTabViews();

        Dialog dialog = new AlertDialog.Builder(getActivity())
                .setTitle(R.string.titel_pallets_bakken)
                .setView(view)
                .create();
        return dialog;
    }

    private void mapCategoriesToHashMaps(){
        ArrayList<CarrierCategory> carrierCategoriesAL = mApi.getAllCarrierCategories();
        carrierCategories = new HashMap<Long, CarrierCategory>();
        carrierCategoriesViewIndicators = new HashMap<Long, View>();
        indicatorCarrierTypes = new HashMap<Long, ArrayList<CarrierType>>();
        if(carrierCategoriesAL != null) {
            for (CarrierCategory cc : carrierCategoriesAL) {
                carrierCategories.put(cc.getID(), cc);
            }
            for (CarrierCategory category : carrierCategoriesAL) {
                if (!carrierCategoriesViewIndicators.containsKey(category)) {
                    carrierCategoriesViewIndicators.put(category.getID(), layoutInflater.inflate(R.layout.tab_view_carrier, null));
                    indicatorCarrierTypes.put(category.getID(), new ArrayList<CarrierType>());
                }
            }
        }
    }

    private void mapCarrierTypesToHashMaps(){
        carrierTypes =  mApi.getAllCarrierTypes();
        for(CarrierType carrierType : carrierTypes){
            if(carrierType.getCarrierCategoryID() != null){
                long carrierTypeId = carrierType.getCarrierCategoryID();
                if(carrierCategoriesViewIndicators.containsKey(carrierType.getCarrierCategoryID()))
                    indicatorCarrierTypes.get(carrierTypeId).add(carrierType);
                else{
                    carrierCategoriesViewIndicators.put(carrierTypeId, layoutInflater.inflate(R.layout.tab_view_carrier, null));
                    indicatorCarrierTypes.put(carrierTypeId, new ArrayList<CarrierType>());
                    indicatorCarrierTypes.get(carrierTypeId).add(carrierType);
                }
            } else {
                //TODO remove after test
                if(carrierCategoriesViewIndicators.containsKey(otherCategory.getID()))
                    indicatorCarrierTypes.get(otherCategory.getID()).add(carrierType);
                else{
                    carrierCategoriesViewIndicators.put(otherCategory.getID(), layoutInflater.inflate(R.layout.tab_view_carrier, null));
                    indicatorCarrierTypes.put(otherCategory.getID(), new ArrayList<CarrierType>());
                    indicatorCarrierTypes.get(otherCategory.getID()).add(carrierType);
                    carrierCategories.put(otherCategory.getID(), otherCategory);
                }
            }
        }
    }

    private void setTabViews() {
        for(long catId : carrierCategoriesViewIndicators.keySet()){
            Bundle b = new Bundle();
            View indicator = carrierCategoriesViewIndicators.get(catId);
            indicator.setBackgroundResource(R.drawable.carrier_tab);
            TextView werkplekIndicatorTitle = (TextView) indicator
                    .findViewById(R.id.text_category_name);
            werkplekIndicatorTitle.setText(carrierCategories.get(catId).getName());
            werkplekIndicatorTitle.setTextColor(Color.WHITE);
            b.putString("key", carrierCategories.get(catId).getName());
            b.putParcelableArrayList("carriertypes", indicatorCarrierTypes.get(catId));
            mTabHost.addTab(
                    mTabHost.newTabSpec(carrierCategories.get(catId).getName()).setIndicator(carrierCategoriesViewIndicators.get(catId)),
                    CreateCarrierTabFragment.class, b);
        }
    }

}
包nl.raakict.android.spc.Fragment;
导入android.app.AlertDialog;
导入android.app.Dialog;
导入android.graphics.Color;
导入android.os.Bundle;
导入android.support.v4.app.DialogFragment;
导入android.support.v4.app.FragmentTabHost;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.widget.TextView;
导入java.util.ArrayList;
导入java.util.HashMap;
导入nl.raakict.android.spc.Controller.API;
导入nl.raakict.android.spc.Model.CarrierCategory;
导入nl.raakict.android.spc.Model.CarrierType;
导入nl.raakict.android.spc.R;
公共类PopupCreateCharrier扩展了DialogFragment{
私有碎片选项卡主机mTabHost;
私有API mApi;
私有ArrayList载体类型;
私有HashMap载体类别;
私有HashMap carrierCategoriesViewIndicators;
私有HashMap指示符载波类型;
私人停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场停车场;
私人承运人类别其他类别;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//layoutInflater=layoutInflater.from(getActivity());
//最终视图=LayoutFlater.充气(R.layout.fragment\u tab\u host\u new\u carrier,空);
//indicatorCarrierTypes=新HashMap();
//mApi=API.getInstance(getActivity());
//mApi.GetCarrierCategories(本);
//mTabHost=(FragmentTabHost)view.findviewbyd(android.R.id.tabhost);
//mTabHost.setup(getActivity(),getActivity().getSupportFragmentManager(),R.id.realtabcontent);
//otherCategory=新载体类别();
//其他类别。设置名称(“Overig”);
//otherCategory.setID(长最大值);
}
@凌驾
创建对话框上的公共对话框(Bundle savedInstanceState){
layoutInflater=layoutInflater.from(getActivity());
最终视图=LayoutFlater.充气(R.layout.fragment\u tab\u host\u new\u carrier,空);
otherCategory=新载体类别();
其他类别。设置名称(“Overig”);
otherCategory.setID(长最大值);
indicatorCarrierTypes=新HashMap();
mApi=API.getInstance(getActivity());
mTabHost=(FragmentTabHost)view.findViewById(R.id.tabhost2);
视图测试=View.findviewbyd(R.id.realtabcontent2);
mTabHost.setup(getActivity(),getActivity().getSupportFragmentManager(),R.id.realtabcontent2);
mapCategoriesToHashMaps();
mapCarrierTypesToHashMaps();
setTabViews();
Dialog Dialog=新建AlertDialog.Builder(getActivity())
.setTitle(右字符串.托盘\u bakken)
.setView(视图)
.create();
返回对话框;
}
私有void mapCategoriesToHashMaps(){
ArrayList carrierCategoriesAL=mApi.getAllCarrierCategories();
carrierCategories=新HashMap();
carrierCategoriesViewIndicators=新HashMap();
indicatorCarrierTypes=新HashMap();
if(carrierCategoriesAL!=null){
for(CarrierCategory抄送:carrierCategoriesAL){
carrierCategories.put(cc.getID(),cc);
}
对于(CarrierCategory类别:carrierCategoriesAL){
如果(!carrierCategoriesViewIndicators.ContainersKey(类别)){
carrierCategoriesViewIndicators.put(category.getID(),layoutFlater.充气(R.layout.tab_view_carrier,null));
indicatorCarrierTypes.put(category.getID(),newArrayList());
}
}
}
}
私有void mappcarrierTypesToHashMaps(){
carrierTypes=mApi.getAllCarrierTypes();
对于(CarrierType CarrierType:carrierTypes){
if(carrierType.getCarrierCategoryID()!=null){
long carrierTypeId=carrierType.getCarrierCategoryID();
if(carrierCategoriesViewIndicators.containsKey(carrierType.GetCarrierCategoriId())
indicatorCarrierTypes.get(carrierTypeId).add(carrierType);
否则{
carrierCategoriesViewIndicators.put(carrierTypeId,layoutFlater.充气(R.layout.tab_view_carrier,null));
indicatorCarrierTypes.put(carrierTypeId,new ArrayList());
indicatorCarrierTypes.get(carrierTypeId).add(carrierType);
}
}否则{
//测试后要删除的TODO
if(carrierCategoriesViewIndicators.containsKey(otherCategory.getID()))
indicatorCarrierTypes.get(otherCategory.getID()).add(carrierType);
否则{
carrierCategoriesViewIndicators.put(otherCategory.getID(),layoutFlater.充气(R.layout.tab_view_carrier,null));
indicatorCarrierTypes.put(otherCategory.getID(),new ArrayList());
indicatorCarrierTypes.get(otherCategory.getID()).add(carrierType);
carrierCategories.put(otherCategory.getID(),otherCategory);
}
}
}
}
私有void setTabViews(){
对于(长catId:carrierCategoriesViewIndicators.keySet()){
Bundle b=新Bundle();
视图指示器=carrierCategoriesViewIndicators.get(catId);
指标.立根资源(R.可提取.载体标签);
TextView WERKPLEKINDICATORTLE=(TextView)指示器
.findViewById(R.id.text\u类别\u n