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 (r.id.goback);
In fragment, the initialization is:
1 back = (ImageButton) View.findviewbyid (r.id.back);
Question two: The question of this
In the activity. Like what:
1 New Simpleadapter (Thisnew string[]{"itemimage"," Itemtext"},newint[]r.id.itemimage,r.id.itemtext});
And in the fragment, you need to:
1 New Simpleadapter (Getactivity (), new tring[]"itemimage", " Itemtext"},newint[]{r.id.itemimage,r.id.itemtext});
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