更改 Android 选项卡小部件内的视图
因此,我的选项卡布局按照 Android 示例 中所示工作:
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);
现在,在选项卡的一项活动中,我声明了一个按钮,并希望引入一个新视图。如果我创建一个新意图,它将推送一个新视图,并且选项卡将消失。是否可以将当前选择的视图切换为新视图?
So I have my tab layout working as demonstrated in the 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);
Now, in one of the tab's activities I've declared a button and would like to bring in a new view. If I create a new intent it will push a new view and the tabs are gone. Is it possible to switch the currently selected view with a new view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,很有可能..您必须使用 ActivityGroup 来实现此目的..
而不是向 TabHost 添加活动..您必须添加 ActivityGroup..
每个活动组都有其活动..
这很容易实现
我有同样的问题但完全解决了检查以下链接
http://ericharlow.blogspot.com/2010/09/experience-multiple-android-activities.html
它是我的解决方案。希望它也能帮助你
Yes it is very much possible .. You have to use ActivityGroup for this purpose..
Instead of Adding a activity to a TabHost.. You have to add ActivityGroup..
Each Activity Group is having its Activity..
THis is simple to implement
I have the same issue but got it totaly RESOLVED Check The Following Link
http://ericharlow.blogspot.com/2010/09/experience-multiple-android-activities.html
Its The Solution For Me . Hope It will Help You as Well