android - 每次点击android时如何刷新选项卡内容

标签 android android-tabhost android-tabs

我在 android 中拥有三个不同内容的三个选项卡。每个选项卡从服务器检索数据并将其显示为 ListView (即三个选项卡上的三个 ListView )。我需要每次都在每个选项卡上刷新。但它会刷新仅第一次点击选项卡。我该如何解决这个问题?

我的代码: tabHost = getTabHost(); getTabHost().invalidate();

    tabHost.addTab(tabHost.newTabSpec("tab1")
            .setIndicator("", getResources().getDrawable(R.drawable.home))
            .setContent(new Intent(this, Home.class)));

    tabHost.addTab(tabHost.newTabSpec("tab2")
            .setIndicator("", getResources().getDrawable(R.drawable.trip))
            .setContent(new Intent(this, Tript.class)));

    tabHost.addTab(tabHost
            .newTabSpec("tab3")
            .setIndicator("",
                    getResources().getDrawable(R.drawable.settings))
            .setContent(new Intent(this, Settings.class)));

    tabHost.setCurrentTab(0);

我现在通过以下方式解决了:

.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

最佳答案

像这样使用 .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)

tabHost.addTab(tabHost.newTabSpec("Your Tab")
    .setIndicator("tab indicator")
    .setContent(new Intent(this, TabClass.class)
    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

关于android - 每次点击android时如何刷新选项卡内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16892959/

相关文章:

android - 无法使用 SearchView 提交查询

java - 渐进式图像渲染,逐像素加载图像并在 imageLoader 中更新 ImageView

android - PagerSlidingTabStrip-如何从右到左选项卡

android - 如何更改 android Tabhost 中的选项卡内容?

Android ActionBar 选项卡设置最初选择的选项卡

android-fragments - Tablayout 更新自定义 View 选项卡的页面标题

android - 如何在不更新文件的情况下构建文件 Uri?

android - 从 PreferenceFragment 访问 ListView

android - 尝试在 TabHost 中打开 WebView

java - Android TabListener : onTabSelected - add fragment to back stack