Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android FragmentTabHost和ChildFragment-未显示ChildFragment_Android_Android Fragments_Fragment Tab Host - Fatal编程技术网

Android FragmentTabHost和ChildFragment-未显示ChildFragment

Android FragmentTabHost和ChildFragment-未显示ChildFragment,android,android-fragments,fragment-tab-host,Android,Android Fragments,Fragment Tab Host,我遵循一个教程,对片段中的两个子片段进行选项卡导航。但在我的例子中,只显示了两个tabindicator,但没有附加子片段 父片段 public class WifisFragment extends SherlockFragment { private static final String TAG = WifisFragment.class.getName(); private static final String TAG1 = TAG + 1; private

我遵循一个教程,对片段中的两个子片段进行选项卡导航。但在我的例子中,只显示了两个tabindicator,但没有附加子片段

父片段

public class WifisFragment extends SherlockFragment {

    private static final String TAG = WifisFragment.class.getName();
    private static final String TAG1 = TAG + 1;
    private static final String TAG2 = TAG + 2;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.wifis_tab_host_layout,
                container, false);

        FragmentTabHost tabHost = (FragmentTabHost) root
                .findViewById(android.R.id.tabhost);

        tabHost.setup(getSherlockActivity(), getChildFragmentManager(),
                android.R.id.tabcontent);

        Bundle arg = new Bundle();
        arg.putInt(ChildFragment.POSITION_KEY, 1);
        TabSpec tabSpec = tabHost.newTabSpec(TAG1).setIndicator("First");
        tabHost.addTab(tabSpec, ChildFragment.class, arg);

        arg = new Bundle();
        arg.putInt(ChildFragment.POSITION_KEY, 2);
        tabSpec = tabHost.newTabSpec(TAG2).setIndicator("Second");
        tabHost.addTab(tabSpec, ChildFragment.class, arg);

        return root;
    }
}
子片段:

public class ChildFragment extends SherlockFragment implements OnClickListener {

    public static final String POSITION_KEY = "FragmentPositionKey";
    private int position;

    public static ChildFragment newInstance(Bundle args) {
        ChildFragment fragment = new ChildFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        position = getArguments().getInt(POSITION_KEY);
        if(CommonUtils.isDebuggable) {
            Log.d("position", "" + position);
        }
        View root = inflater.inflate(R.layout.fragment_child, container, false);
        TextView textview = (TextView) root.findViewById(R.id.textViewPosition);
        textview.setText(Integer.toString(position));
        textview.setOnClickListener(this);

        return root;
    }

    @Override
    public void onClick(View v) {
        Toast.makeText(v.getContext(), "Clicked Position: " + position, Toast.LENGTH_LONG).show();
    }
}
父片段的XML布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:pixlui="http://schemas.android.com/apk/com.neopixl.pixlui"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.neopixl.pixlui.components.textview.TextView
        android:id="@+id/header_text"
        android:background="@color/menu_color"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:minHeight="@dimen/textview_height"
        android:padding="10dp"
        android:text="@string/wifi"
        android:textColor="@android:color/white"
        android:textSize="18sp"
        pixlui:copyandpaste="false"
        pixlui:typeface="aleo_bold.ttf" />

    <android.support.v4.app.FragmentTabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <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="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1" />
        </LinearLayout>
    </android.support.v4.app.FragmentTabHost>

</LinearLayout>


你能告诉我到底是什么问题吗?

我的代码中没有任何问题。我使用的是一个旧的android support-v4库。然后我将库版本更改为最新版本(19.0.1),一切正常