在TabHost设置中选择容器,“未找到ID的视图”

巴特·伯格

我正在创建一个对话框,其中有x个选项卡,用户可以从中进行选择。这种情况的独特之处在于我已经为我的Activity安装了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);
        }
    }

}

请注意,如果我将其指向其他TabHost的容器,它确实可以工作,但是当然会更改错误的容器。

巴特·伯格

我的观点并没有直接针对该活动,因此我使用了错误的FragmentManager,而我必须使用的是getChildFragmentManager()。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Nginx 未找到文件,但从 mysql 中选择信息

来自分类Dev

剔除js,从树状视图中选择的项目中找到所有父节点ID

来自分类Dev

敲除js,从树状视图中选择的项目中找到所有父节点ID

来自分类Dev

数据绑定、TabLayout 和“未找到片段 ID 的视图”

来自分类Dev

未找到列:1054“ where子句”中的未知列“ id”(SQL:从“ item”中选择count(*)作为汇总,其中“ barcode” = A002和`id` <> 12)

来自分类Dev

如果由于权限,在Sitecore多列表中选择隐藏[未找到项目]的方法吗?

来自分类Dev

在视图选择中选择语句

来自分类Dev

如何设置具有绑定的ViewPager和TabLayout?(IllegalArgumentException:未找到视图)

来自分类Dev

工具提示容器未找到错误

来自分类Dev

骨干嵌套视图无法找到ID选择器

来自分类Dev

ViewPager作为listview行java.lang.IllegalArgumentException:未找到ID的视图

来自分类Dev

butterknife字段“ hello”的ID为2131427413的必需视图“ hello”未找到

来自分类Dev

Android Navigation Drawer:未找到 ID 0x7f0d0084 的视图

来自分类Dev

Android:自定义 AlertDialog,viewPager:java.lang.IllegalArgumentException:未找到 id 的视图

来自分类Dev

Highcharts投掷容器未找到错误,但容器存在

来自分类Dev

在Lumen 5.2.6上,InvalidArgumentException,“未找到视图”

来自分类Dev

Laravel基表或视图未找到

来自分类Dev

在Lumen 5.2.6上,InvalidArgumentException,“未找到视图”

来自分类Dev

未找到结尾为数字的视图

来自分类Dev

未找到基表或视图错误

来自分类Dev

Django 2 - 未找到视图的反向

来自分类Dev

未找到 Django、URL 和视图

来自分类Dev

在mongo ID中选择*

来自分类Dev

JPA 从视图中选择

来自分类Dev

如何选择表中未找到的值?

来自分类Dev

从具有ID的容器中选择<span>子级并更改文本颜色

来自分类Dev

在选择器下拉列表中选择名称时,如何设置状态 ID?

来自分类Dev

设置在CheckComboBox中选择的项目

来自分类Dev

在文档中找到正确的 id 后从多个集合中选择数据

Related 相关文章

  1. 1

    Nginx 未找到文件,但从 mysql 中选择信息

  2. 2

    剔除js,从树状视图中选择的项目中找到所有父节点ID

  3. 3

    敲除js,从树状视图中选择的项目中找到所有父节点ID

  4. 4

    数据绑定、TabLayout 和“未找到片段 ID 的视图”

  5. 5

    未找到列:1054“ where子句”中的未知列“ id”(SQL:从“ item”中选择count(*)作为汇总,其中“ barcode” = A002和`id` <> 12)

  6. 6

    如果由于权限,在Sitecore多列表中选择隐藏[未找到项目]的方法吗?

  7. 7

    在视图选择中选择语句

  8. 8

    如何设置具有绑定的ViewPager和TabLayout?(IllegalArgumentException:未找到视图)

  9. 9

    工具提示容器未找到错误

  10. 10

    骨干嵌套视图无法找到ID选择器

  11. 11

    ViewPager作为listview行java.lang.IllegalArgumentException:未找到ID的视图

  12. 12

    butterknife字段“ hello”的ID为2131427413的必需视图“ hello”未找到

  13. 13

    Android Navigation Drawer:未找到 ID 0x7f0d0084 的视图

  14. 14

    Android:自定义 AlertDialog,viewPager:java.lang.IllegalArgumentException:未找到 id 的视图

  15. 15

    Highcharts投掷容器未找到错误,但容器存在

  16. 16

    在Lumen 5.2.6上,InvalidArgumentException,“未找到视图”

  17. 17

    Laravel基表或视图未找到

  18. 18

    在Lumen 5.2.6上,InvalidArgumentException,“未找到视图”

  19. 19

    未找到结尾为数字的视图

  20. 20

    未找到基表或视图错误

  21. 21

    Django 2 - 未找到视图的反向

  22. 22

    未找到 Django、URL 和视图

  23. 23

    在mongo ID中选择*

  24. 24

    JPA 从视图中选择

  25. 25

    如何选择表中未找到的值?

  26. 26

    从具有ID的容器中选择<span>子级并更改文本颜色

  27. 27

    在选择器下拉列表中选择名称时,如何设置状态 ID?

  28. 28

    设置在CheckComboBox中选择的项目

  29. 29

    在文档中找到正确的 id 后从多个集合中选择数据

热门标签

归档