Understanding Android Fragments: The Basics and Implementation Tips

android fragments n.w
1 / 9
Embed
Share

Learn about Android Fragments, their purpose, usage in activities, adaptability to different screens, lifecycle, adding to activities, and special types from the Android API. Find out how to work with Fragments efficiently.

  • Android Development
  • Fragments
  • User Interface
  • Screen Adaptability
  • Activity Lifecycle

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Android Fragments A very brief introduction Android Fragments 1

  2. Fragments, what and why? Fragments are fragments(!) of an Activity. A Fragment can be re-used in many Activities. Fragments can help you adapt to different screen sizes and resolutions. Most Fragments has a UI (User Interface), but some Fragments has no UI. Fragments were introduced in Android 3.0 Android 3.0 (API level 11) is the tablet version. Android Fragments 2

  3. Fragments used on tablets and phones Picture from http://developer.android.com/guide/components/fragments.html Android Fragments 3

  4. Programming a Fragment Public class MyFragment extends Fragment { } Fragments do not need to register in manifest.xml A Fragments can only be used in an application, when the Fragment is inside an Activity The Fragments UI is defined in a layout XML file Just like an Activity Or the UI can be made programmatically (just like an Activity) Some Fragments might not even have a UI An invisible Fragment Examples: FragmentExampleDateTime Android Fragments 4

  5. The Fragment lifecycle The Fragment lifecycle is similar to the Activity lifecycle. View onCreateView() is the method to override in subclasses. Not onCreate (unlike Activity subclasses) http://docs.xamarin.com/guides/android/platform_features/fragments/part_1_-_creating_a_fragment/ Android Fragments 5

  6. Adding fragment to an Activity Fragment can be added statically or dynamically Statically Declared in the Activities layout XML file Example: FragmentExampleDateTime Dynamically Adapt to the current screen size Show more fragments on bigger screens In the Activities Java file Examples FragmentAddDynamically WorkoutFragments Android Fragments 6

  7. Special Fragments from the Android API DialogFragment Dialog window ListFragment List of items PreferenceFragment User preferences WebViewFragment Small web browser MapFragment Shows a Google Map Android Fragments 8

  8. Single Activity App From web development SPA = Single Page Application Web application with a single page The page content is changed as needed Android: Single Activity App Android apps with a single Activity The Activity content is changed as needed Fragments are handy Example: BasicActivityActivityExample Android Fragments 9

  9. References and further readings Android Developer: Building a Dynamic UI with Fragments http://developer.android.com/training/basics/fragments/creating.html Android Developer: Fragments http://developer.android.com/guide/components/fragments.html Conder & Darcy: Android User Interface Design: Working With Fragments http://mobile.tutsplus.com/tutorials/android/android-sdk_fragments/ Xamarin: Fragments http://docs.xamarin.com/guides/android/platform_features/fragments/ Android Fragments 10

More Related Content