Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 17  Two-Pane Master-Detail Interfaces


Creating tablet alternatives


Because your alias is in res/values/, it is the default alias. So, by default, CrimeListActivity
inflates the single-pane layout.


Now you are going to create an alternative resource so that the activity_masterdetail alias will
point to activity_twopane.xml on larger devices.


In the project tool window, right-click res/values/ and create a new values resource file. As before,
name the file refs.xml and check that its directory is values. But this time, select Smallest Screen
Width under Available qualifiers and click the >> button to move it over to the right (Figure 17.6).


Figure 17.6  Adding a qualifier


This qualifier is a bit different. It asks you to specify a value for the smallest screen width. Enter 600
here, and click OK. Once your new resource file opens, add the activity_masterdetail alias to this
file, too, pointing at a different layout file.


Listing 17.5  Alternative alias for larger devices
(res/values-sw600dp/refs.xml)



@layout/activity_twopane

Let’s explain what you are doing here. Your goal is to have logic that works like this:



  • For devices that are under a specified size, use activity_fragment.xml.

  • For devices that are over a specified size, use activity_twopane.xml.

Free download pdf