Generally, to use tabhost, you only need to inherit tabactivity. In the layout, set the ID @ Android: ID/tabhost. in the class, gettabhost and addtab can be used.
However, this requires that the setcontentview contain the tabhost control in the layout. If it does not contain the tabhost control, the following error is returned:
Java. Lang. runtimeexception: Your content must have a tabhost whose ID attribute is 'android. R. Id. tabhost'
In my case, setcontentview is required in the parent class, And the inflate method is used in the subclass to dynamically load it into tabhost. Therefore, an error is reported when setcontentview of the parent class is used.
The solution is:
Do not use tabactivity to load tabhost.
There is an article on the InternetArticleHttp://jiguansheng.iteye.com/blog/1168804
This article mainly defines the tabhost ID in the layout and finds the tabhost through findviewbyid. The next step is to call the setup () method of tabhost. An error occurred while trying to run:
Did you forget to call 'public void setup (localactivitymanager activitygroup );
In this article get solved http://blog.sina.com.cn/s/blog_9935b660010135xz.html
I inherited the parent class from activitygroup, loaded the layout of the subclass inflate, found the tabhost through findviewbyid, and then called
Tabhost. Setup ();
Tabhost. Setup (this. getlocalactivitymanager ());
Solve the problem.