gpt4 book ai didi

java - 更改 Android 选项卡小部件中的 View

转载 作者:搜寻专家 更新时间:2023-11-01 09:15:52 25 4
gpt4 key购买 nike

因此,我的选项卡布局如 Android example 中所示工作:

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab

// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ArtistActivity.class);

// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tabHost.addTab(spec);

// Do the same for the other tabs
intent = new Intent().setClass(this, AlbumsActivity.class);
spec = tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tabHost.addTab(spec);

intent = new Intent().setClass(this, SongsActivity.class);
spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tabHost.addTab(spec);

现在,在选项卡的一个 Activity 中,我声明了一个按钮并想引入一个新 View 。如果我创建一个新 Intent ,它将推送一个新 View 并且选项卡消失了。是否可以将当前选定的 View 切换为新 View ?

最佳答案

是的,这很有可能。您必须为此目的使用 ActivityGroup。

不是将 Activity 添加到 TabHost.. 您必须添加 ActivityGroup..每个 Activity 组都有自己的 Activity ..

这很容易实现

我有同样的问题,但完全解决了检查以下链接

http://ericharlow.blogspot.com/2010/09/experience-multiple-android-activities.html

它是我的解决方案。希望对你也有帮助

关于java - 更改 Android 选项卡小部件中的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4734539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com