繁体   English   中英

标签刷新(TabHost)

[英]Tab refresh (TabHost)

我使用TabHost设置了2个选项卡,两个选项卡都有一个listview。 我已经设置了每个列表视图,以便当我单击一个项目时,一个动作完成了,可以正常工作,我遇到的问题是我必须重新加载应用程序才能将更新显示在tab2上,我想要的是打开时一个选项卡,每次打开时都会刷新该选项卡的布局。 为了获得布局,我将其包含在选项卡XML中。

我的适配器已经安装并且在MainActivity中工作得很好,仅在添加TabHost之后才出现此问题。

          // My contentMain
                <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <include
                    android:id="@+id/Onglet1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    layout="@layout/layouttab1" />

            </LinearLayout>


          // My adapter
          ArrayAdapter<Store1> adapter = new MyTitleAdapter();
          ListView myList = (ListView) findViewById(R.id.ListView);
          adapterTitle.notifyDataSetChanged();
          myList.setAdapter(adapter); 


    TabHost.TabSpec spec = host.newTabSpec("Tab One");
    spec.setContent(R.id.tab1);

    spec.setIndicator("First Tab");
    host.addTab(spec);

    TabHost host = (TabHost)findViewById(R.id.tabHost);
    host.setup();

    spec = host.newTabSpec("Tab Two");
    spec.setContent(R.id.tab2);
    spec.setIndicator("Secong Tab");
    //host.setOnTabChangedListener();
    host.addTab(spec);

当您在列表视图中添加项目时,请在适配器中调用一种方法(自行创建)

public void refreshWishlistAdapter() {
itemList.clear();
itemList.addAll(dbHelper.getallWishlistItems());
itemsAdapter.notifyDataSetChanged();
}

在片段中使用此方法,因此当您切换片段时,此方法将执行:

private boolean isShown = false;

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    if (getView() != null) {
        isShown = true;
        // fetchdata()  show data when page is selected
        fetchData();
    } else {
        isShown = false;
    }
} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM