Java 添加带有片段内活动的选项卡主机

Java 添加带有片段内活动的选项卡主机,java,android,android-activity,android-fragments,Java,Android,Android Activity,Android Fragments,你好。我有一些问题。 我有一个应用程序,左边是listview,右边是detail view。在右视图中,我有一个带有tab host的片段。但我还想为所有选项卡添加活动。 例如: 我在左边有客户名单。 在右边我有标签:“客户评论”、“客户照片”、“客户信息” 在客户评论中,我需要在活动中对此客户发表评论,并可能添加新评论。 我已经创建了一个列表视图和详细信息,但是我在将选项卡主机集成到其中时遇到了问题。所以我有。这里是我的详细代码片段 public class ItemDetailFragm

你好。我有一些问题。 我有一个应用程序,左边是listview,右边是detail view。在右视图中,我有一个带有tab host的片段。但我还想为所有选项卡添加活动。 例如: 我在左边有客户名单。 在右边我有标签:“客户评论”、“客户照片”、“客户信息” 在客户评论中,我需要在活动中对此客户发表评论,并可能添加新评论。 我已经创建了一个列表视图和详细信息,但是我在将选项卡主机集成到其中时遇到了问题。所以我有。这里是我的详细代码片段

 public class ItemDetailFragment extends Fragment {

        public static final String ARG_ITEM_ID = "item_id";

        DummyContent.DummyItem mItem;
        private Activity lo_parentAct;



        public ItemDetailFragment() {
        }

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if (getArguments().containsKey(ARG_ITEM_ID)) {
                mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
            }
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_item_detail, container, false);
            if (mItem != null) {
                Intent lv_intent;
            //    ((TextView) rootView.findViewById(R.id.item_detail)).setText(mItem.content);
                TabHost tabHost=(TabHost)rootView.findViewById(R.id.tabHost);
                tabHost.setup();

                TabSpec spec1=tabHost.newTabSpec("Tab 1");
                spec1.setIndicator("Общая информация");
                lo_parentAct = this.getActivity();
                lv_intent = new Intent(lo_parentAct, ClientInfoActivity.class);

                TabSpec spec2=tabHost.newTabSpec("Tab 2");
                spec2.setIndicator("Заметки");
                lv_intent = new Intent(lo_parentAct, ClientCommentsActivity.class);

                TabSpec spec3=tabHost.newTabSpec("Tab 3");
                spec3.setIndicator("Фото");
                lv_intent = new Intent(lo_parentAct, ClientPhotosActivity.class);


                tabHost.addTab(spec1);
                tabHost.addTab(spec2);
                tabHost.addTab(spec3);

            }
            return rootView;
        }
    }
布局图

    <TabHost android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/tabHost"
            xmlns:android="http://schemas.android.com/apk/res/android"
            >
        <TabWidget
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@android:id/tabs"
            />
             <FrameLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@android:id/tabcontent"
             >
                 <LinearLayout
                     android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/tab1"
                    android:orientation="vertical"
                    android:paddingTop="60px"
                >
             <TextView  
            android:layout_width="fill_parent" 
            android:layout_height="100px" 
            android:text="This is tab1"
            android:id="@+id/txt1"
            />    

     </LinearLayout>

     <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/tab2"
            android:orientation="vertical"
            android:paddingTop="60px"
             >
         <TextView  
                android:layout_width="fill_parent" 
                android:layout_height="100px" 
                android:text="This is tab 2"
                android:id="@+id/txt2"
                />

     </LinearLayout>

      <LinearLayout
     android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/tab3"
    android:orientation="vertical"
    android:paddingTop="60px"
     >
             <TextView  
            android:layout_width="fill_parent" 
            android:layout_height="100px" 
            android:text="This is tab 3"
            android:id="@+id/txt3"
            />

     </LinearLayout>
     </FrameLayout>

    </TabHost>

添加带有片段内活动的选项卡主机

你不能把活动分成碎片! 据我所知-您想将具有不同
活动的
选项卡activity
(已弃用)放入主活动的根
片段
-这种方式绝对错误

实现您需要的一种方法是:

  • 创建一个
    FragmentActivity
  • 将TabWidget放入
    碎片活动的根布局中
  • 然后将不同的
    片段放入TabWidget的选项卡中
    
    您可以通过代码示例查看我的类似答案。

    但如果我有“SplitView”应用程序,您就有SplitView应用程序。那又怎么样?你能说得更具体些吗?你到底需要什么?现在你的问题是完全不清楚的。安德里奥德没有
    SplitView
    。但是你可以通过安卓
    Fragment
    s实现像SplitView这样的iOS。对不起,我想我明白了。我试试看