与Android TabHost示例问题示例、问题、Android、TabHost

2023-09-12 02:04:52 作者:最后遍体鳞伤

我一直在试图推行高级 tabwidget 例如来自谷歌。但是,当它试图调用 tabHost.addTab(规范); 我从调试器堆栈跟踪。对不起,我没有堆栈跟踪在这里,但我想知道如果其他人有同样的问题(因为这code有一些错字的和失踪,从连汇编拦住了我的信息。

任何人都可以点我这个code校正/运行的版本?

所需的最新信息是:

 <活动机器人:名称=。ArtistsActivity>< /活性GT;
<活动机器人:名称=。AlbumsActivity>< /活性GT;
<活动机器人:名称=。SongsActivity>< /活性GT;
 

解决方案

目前的 TabHost 的例子在Android开发者网站包含一个错误,也留下了,​​将prevent的例子运行的重要一步。

第一关: 在被添加到HelloTabWidget类的onCreate()方法试图使用称为mTabHost一个TabHost对象。这是无效的,它应该是tabHost

二: 本教程离开了,你需要添加的每一项活动的太AndroidManifest.xml中的细节。如果没有这个的code将无法正常工作,您将获得每次试图执行时间强制关闭。

I have been attempting to implement the 'advanced' tabwidget example from google. But, when it tries to call tabHost.addTab(spec); I get a stack trace from the debugger. Sorry, I don't have the stack trace here, but I'm wondering if others have had this same issue (as this code had a number of typo's and missing information that stopped me from even compiling.

Android Tabhost选项卡

Can anyone point me to a corrected/running version of this code?

The updated information needed are:

<activity android:name=".ArtistsActivity"></activity>
<activity android:name=".AlbumsActivity"></activity>
<activity android:name=".SongsActivity"></activity>

解决方案

The current TabHost Example on the Android Developers site contains one error and also leaves out an important step that will prevent the example from running.

First off: In the onCreate() method that is added to HelloTabWidget class attempts to use a TabHost object called mTabHost. This is invalid, it should be tabHost.

Second: The tutorial leaves out the details that you need to add each of the activities too the AndroidManifest.xml. Without this the code will not work and you will get "force close" each time you attempt to execute.