Once you've decided on a screen detection strategy, using either pure Java or resource selectors, you then have to make decisions on what sort of layout to present to the user. On smaller screens such as cell phones, It is common to only present one fragment at at time, with the current fragment filling the entire current activity. On a larger screen such as a tablet, you might present two fragments side-by-side.
- [Instructor] Once you've detected…what kind of device your app is running on,…you can decide what kind of layout you want to present.…In this version of my application,…I've added a few different components.…First of all, I've added a second activity…that I've named DetailActivity.…It uses this layout file called ActivityDetail.XML,…and that in turn includes a content_detail file.…This content_detail has a fragment,…and the fragment is called DetailActivityFragment,…and it uses this XML layout file…that has a TextView that simply presents the text,…this is the fragment.…
So if I were to simply navigate to the DetailActivity,…that's the text that I would see.…And that's what I would want to do on a phone.…But on a tablet, I might want to present my primary fragment…and my detail fragment side-by-side.…In my MainActivity class, I already have code in place…to detect what kind of device I'm working on.…And I've added a FloatingActionButton…that executes this method, viewDetailFragment,…and that's where I'll place my conditional code.…
Author
Released
9/1/2016- Configuring Android Studio
- Understanding fragments
- Creating a fragment class and layout
- Adding and removing fragments with Java
- Creating layouts for multiple screens
- Understanding arguments and callback methods
- Passing arguments to a fragment
- Choosing layout at runtime
- Displaying dialogs with fragments
- Using fragments for managing dialogs, shared preferences, and more
Skill Level Intermediate
Duration
Views
-
Introduction
-
Welcome1m 4s
-
What you should know1m 50s
-
Using the exercise files1m 39s
-
-
1. Getting Started
-
Understanding fragments3m 17s
-
2. Display Fragments in Activities
-
Display a fragment with XML3m 16s
-
Add a fragment with Java3m 50s
-
3. Manage Fragments at Runtime
-
Pass arguments to a fragment5m 18s
-
Choose layout at runtime3m 21s
-
-
4. Communication between Fragments and Activities
-
5. Display Dialogs with Fragments
-
Display a custom dialog5m 1s
-
Pass arguments to the dialog4m 16s
-
6. Other Uses of Fragments
-
Create a ViewPager adapter4m 53s
-
Conclusion
-
Next steps1m 11s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Choose layout at runtime