Changes

Jump to: navigation, search

Using Fragments in Android - A Worked Example

300 bytes added, 17:47, 17 May 2013
no edit summary
[[Image:android_verify_support_library.png|Checking the Android Support Library package is installed]]
Figure 21-1
With the Android Support Library installed, the next step is to verify that it is already included in the project. Remaining within the Eclipse environment, locate the FragmentExample project within the Package Explorer panel and unfold the libs folder. If the support library is already included in the project, it will be listed as android-support-v4.jar:
[[Image:android_support_library_added.png|The android support library in the Eclipse Package Explorer]]
Figure 21-2
[[Image:android_fragment_one_ui.png|The UI for the first Fragment]]
Figure 21-3
[[Image:android_fragment_two_ui.png|The UI for the second Fragment]]
Figure 21-4
As with the first fragment, this one will also need to have a class associated with it. Unfold the src category under the FragmentExample project (if it is not already unfolded) in the Package Explorer panel and right-click on the package name given to the project when it was created. From the resulting menu, select the New -> Class option. Using the same steps as those for the first fragment, name the fragment TextFragment and set the Superclass field to Fragment - android.support.v4.app. Click Finish to create the class.
Edit Edit the new TextFragment.java class file and modify it to implement the onCreateView() method:
<pre>

Navigation menu