Changes

Jump to: navigation, search

Using Fragments in Android - A Worked Example

30 bytes added, 19:48, 1 July 2013
Creating the First Fragment Class
In addition to a user interface layout, a fragment also needs to have a class associated with it to do the actual work behind the scenes. Add a class for this purpose to the project by unfolding the src folder under the FragmentExample project in the Package Explorer panel and right-clicking on the package name given to the project when it was created
(for example com.example.fragmentexample). From the resulting menu, select the New -> Class option. In the resulting New Java Class dialog, name the class ToolbarFragment. Next, click on the Browse button to the right of the Superclass field. In the superclass selection dialog, enter Fragment into the text box. From the matching items list, locate and double click on the Fragment - android.support.v4.app entry (selecting the android.app instance of the class will not make use of the support library precluding the execution of the application on older Android versions).
 
<google>BUY_ANDROID</google>
Click Finish to complete the class creation process. Once the class has been created, it should, by default, appear in the editing panel where it will read as follows:

Navigation menu