Fragment problem Set

Source: Internet
Author: User

Recently made an app, because in the MU class online learning new ways to do tab (app main interface) effect, so just learned not long used up

Using the fragment to implement the Tab method

Query for an afternoon of Android data, about this thing is after Android 3.0 version out, in order to facilitate the control of the main interface, make the code easier to complete and easier to post-maintenance

How to say, fragment is a child activity

Mu class net is just point to how to use fragment to build tab, but use up, write code in fragment don't say

Self-made, the beginning is according to the activity of the method to do, the results found a lot of problems, Baidu a bit, to solve a part, because the initial use of fragment so will be found in the future more problems, so this will be about the fragment of the problems summarized

Problem one: the use of controls

Layout files. XML is used the same way as in activity

But it's not the same in the. java file, like ImageButton

Private ImageButton Image_country_zhong;

Then the initialization in the activity is:

1 back = (ImageButton) Findviewbyid (;

In fragment, the initialization is:

1     back = (ImageButton) View.findviewbyid (;

Question two: The question of this

In the activity. Like what:

1  New Simpleadapter (Thisnew string[]{"itemimage","  Itemtext"},newint[],});  

And in the fragment, you need to:

1  New Simpleadapter (Getactivity (),       new tring[]"itemimage", " Itemtext"},newint[]{,});  

The difference is: the first parameter, the activity of this is replaced by the fragment in the Getactivity (), fragemnt and activity is the host and relying on the relationship, the use of similar, but must rely on activity, In Fragement the context of the volume must be given the host context

Not to be continued!

Fragment problem Set

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: 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.