Do not inherit tabactivity definition tabhost

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.