0

单击选项卡时,如何保留相同的 contentView,并且仅调用在列表中应用过滤器来更改元素的方法?如果我不设置“setContent”属性,我会得到“您必须指定一种创建选项卡内容的方法”,但我不想仅为列表中的某些更改创建新视图!

这里创建和控制选项卡的类

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

    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.implant_fragment, container, false);

    // Take implant listView
    _lv_imp = (ListView) view.findViewById(android.R.id.list);

    _tabHost = (TabHost) getActivity().findViewById(R.id.tabHost);

    // Tab1
    TabHost.TabSpec todoImpTab = _tabHost.newTabSpec("todo");
    // set title and icon
    todoImpTab.setIndicator("Impianti DA FARE");

// ******** Here invoke the method for change the content of listView when tab clicked ****
    filterTodoImplant();

    // Tab2
    TabHost.TabSpec allImpTab = _tabHost.newTabSpec("all");
    allImpTab.setIndicator("TUTTI gli impianti");

    listDBImplants();

    // Add tabspec to tabHost
    _tabHost.addTab(todoImpTab);
    _tabHost.addTab(allImpTab);

    return view;
}

这里是布局文件

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<!-- Fragment container -->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools"
             android:id="@+id/fragment_container"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:paddingLeft="@dimen/activity_horizontal_margin"
             android:paddingRight="@dimen/activity_horizontal_margin"
             android:paddingTop="@dimen/activity_vertical_margin"
             android:paddingBottom="@dimen/activity_vertical_margin"
             tools:context=".MainActivity" />

<!-- Tab host for filter list elements -->
<TabHost
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/tabHost"
        android:layout_gravity="center">

    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">

        <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
        </TabWidget>

        <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
        </FrameLayout>

    </LinearLayout>
</TabHost>

<!-- nav drawer list -->
<ListView android:id="@+id/lv_drawer_list"
          android:layout_width="240dp"
          android:layout_height="match_parent"
          android:layout_gravity="start"
          android:choiceMode="singleChoice"
          android:divider="@android:color/transparent"
          android:dividerHeight="0dp"
          android:background="#2A262F" />

4

0 回答 0