title: Android: How to use string resource from xml file in property of customized preference?
body: <p>I've implemented a custom seekbar preference, using this site - <a href="http://robobunny.com/wp/?p=190" rel="nofollow noreferrer">seekbar preference</a> and it works just fine. Now I want to add values to the seekbar's customized properties from the <code>string.xml</code> file instead of hard-coding them:<br>
  Instead of writing <code>customseekbar:unitsRight="Seconds"</code> I want to have a string resource like <code>&lt;string name="units"&gt;Seconds&lt;/string&gt;</code> and use it like this: <code>customseekbar:unitsRight="@string/units"</code>. I've tried to implement this <a href="https://developer.android.com/training/custom-views/create-view.html" rel="nofollow noreferrer">guide</a>. My relevant code is:<br>
  <strong>attrs.xml</strong>  </p>
  
  <pre><code>&lt;resources&gt;
  &lt;declare-styleable name="CustomSeekBarPreference"&gt;
      &lt;attr name="unitsRight" format="reference|string"/&gt;
  &lt;/declare-styleable&gt;
  </code></pre>
  
  <p>
  And the constructor -<br>
  <strong>CustomSeekBarPreference.java</strong>  </p>
  
  <pre><code>public class CustomSeekBarPreference extends Preference implements SeekBar.OnSeekBarChangeListener {
  
      private static final String APPLICATIONNS="http://CustomSeekBarPreference.com";
      public CustomSeekBarPreference(Context context, AttributeSet attrs) {
          super(context, attrs);
          TypedArray a = context.obtainStyledAttributes(
              attrs, R.styleable.CustomSeekBarPreference, 0 ,0);
          mUnitsRight = a.getString(R.styleable.CustomSeekBarPreference_unitsRight);
          a.recycle();
  }
  </code></pre>
  
  <p>and the <strong>layout</strong> -   </p>
  
  <pre><code>&lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:customseekbar="http://CustomSeekBarPreference.com" &gt;
  
  &lt;com.x.sharedpreferencestestapp.CustomSeekBarPreference
      android:key="1"
      android:defaultValue="30"
      android:max="100"
      customseekbar:min="0"
      android:title="Default step"
      customseekbar:unitsRight="@string/units"/&gt;
  &lt;/PreferenceScreen&gt;
  </code></pre>
  
  <p>But as you can see, I get 'null' instead of the right value: <a href="https://i.stack.imgur.com/CTmF3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CTmF3.png" alt="screenshot"></a>
  Even if I change the value to a fixed string instead of string resource, like <code>customseekbar:unitsRight="Seconds"</code> I still get the same result. And just to make it clear - if I stick to the original code of the seekbar preference: <code>mUnitsRight = getAttributeStringValue(attrs, APPLICATIONNS, "unitsRight", "defaultValue")</code> it works, but not with string resource.</p>