title: Android resource selection layout- and values- inconsistencies
body: <p>The issue I am experiencing indicates that the resource bucket being selected for a given activity's <code>layout</code> XML is inconsistent with the resources being selected from the <code>values</code> folder despite the exact same resource qualifiers being used in each set of folders.</p>
  
  <h2>Example</h2>
  
  <p>After placing some logging code within my application's abstract parent activity I can see that when starting my application over a Nexus 7 type emulator (Android 4.1) the smallest width is indeed 600dp, the <code>layout-sw600dp-*</code> folder is being used to fetch the UI for the activity but the folder being used for the <code>values</code> is <code>values-large-*</code>. I was expecting this to be <code>values-sw600dp-*</code> thus providing me with the vital information as to what resource bucket the activity is running under.</p>
  
  <p>Code doing the logging within my app's parent activity for all <code>android.app.Activity</code>s</p>
  
  <pre><code>  protected void onCreate(final Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      final Configuration config = getResources().getConfiguration();
      Log.i(this.getClass().getSimpleName(), String.format("Smallest width is [%s]", config.smallestScreenWidthDp));
      configurationContext = SupportedDeviceConfiguration.fromResourceQualifer(getString(string.resourceQualifier));
      Log.i(this.getClass().getSimpleName(), String.format("Running under the [%s] configuration context.", configurationContext.getResourceQualifier()));
  ...
  </code></pre>
  
  <p>Logging output from when I run this code on a Nexus 7 type device;</p>
  
  <pre><code>[Logging fluff] Smallest width is [600]
  [Logging fluff] Running under the [layout-large-land] configuration context.
  </code></pre>
  
  <p>I know what you are thinking - where did that <em>layout-large-land</em> derivation come from? Read on...</p>
  
  <h2>Background</h2>
  
  <p>I am trialling an approach outlined <a href="https://stackoverflow.com/a/11670441/1348379">here</a> which would allow me to inspect the resources bucket under use at runtime. Essentially the approach I have implemented has the following structure of resource qualifiers;</p>
  
  <pre><code>- res
    + layout                   // Default portrait layout.
    + layout-land              // Default landscape layout
    + layout-large-land        // pre 3.2 phablet landscape layout (Galaxy Note at v2.3.3)
    + layout-xlarge-land       // pre 3.2 tablet landscape layout
    + layout-xlarge-port       // pre 3.2 tablet portrait layout
    + layout-sw520dp-port      // post 3.1 phablet portrait layout (Galaxy Note at v4.0.3)
    + layout-sw520dp-land      // post 3.1 phablet landscape layout
    + layout-sw600dp-port      // post 3.1 mini-tablet portrait layout (Nexus 7)
    + layout-sw600dp-land      // post 3.1 mini-tablet-landscape layout 
    + layout-sw700dp-port      // post 3.1 tablet portrait layout
    + layout-sw700dp-land      // post 3.1 tablet landscape layout
    - values                   // Contains the root strings.xml
       strings.xml
    - values-land
       default-config.xml            
    - values-large-land
       default-config.xml        
    - values-xlarge-land
       default-config.xml     
    - values-xlarge-port
       default-config.xml     
    - values-sw520dp-port
       default-config.xml     
    - values-sw520dp-land
       default-config.xml     
    - values-sw600dp-port
       default-config.xml     
    - values-sw600dp-land
       default-config.xml     
    - values-sw700dp-port
       default-config.xml     
    - values-sw700dp-land
       default-config.xml
  </code></pre>
  
  <p>So essentially the <code>values</code> qualifiers reflect that of the <code>layout</code> qualifiers. Under each of <code>values-*</code> folders I have defined a single XML file called <code>device-config.xml</code> with content;</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
      &lt;string name="resourceQualifier"&gt;layout-{qualifier of values folder}&lt;/string&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>So, for example the <code>values-sw600dp-land</code> folder's <code>device-config.xml</code> contains a single string with value <code>layout-sw600dp-land</code>. The objective here is for my code to remain in-sync with the resource layouts being displayed on screen. This is needed so that my code doesn't go off "finding by id" some item which doesn't exist on the displayed layout owing to the real-estate involved.</p>
  
  <h3>(Optional) Deeper reasoning for why I am doing this</h3>
  
  <p>The deeper reasoning for wanting to know the bucket being used at runtime was born out of the realisation that my single-fragment-for-all-configurations code was becoming difficult to manage with various switch based logic which was not transparent and often duplicated features from other layouts...it was as if I needed some sort of <a href="https://dl.dropbox.com/u/17614325/SwellFragments.png" rel="noreferrer">Fragment Inheritance</a> ...which if you follow the link is exactly what I did. The downside of this is that I need to know what screen I am working with before instructing the framework to instantiate the x, y, or z fragment, safe in the knowledge that the Fragment being created will never be out of sync with the layout it is meant to inflate. This inheritance works and allows for a far more manageable fragment stack (Sonar is happier too which is nice).</p>
  
  <h2>Summary</h2>
  
  <p>However, I have been thwarted by this apparent discrepancy between which layout folder and values folder the framework selects. Each have the same qualifiers therefore why doesn't an Activity leveraging the  <code>layout-sw600dp-land</code> UI XML use the <code>values-sw600dp-land</code> resource? I am hoping I've got something wrong because it was the neatest of the potential solutions posted on the SO discussion I linked to above.</p>