title: Get integer value from dimens.xml resource file in Android
body: <p>I have an <strong>EditText</strong> which is decimal and I set its length using <strong>android:maxLength</strong> property in xml:</p>
  
  <pre><code>    &lt;EditText
          android:id="@+id/quantity"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:ems="10"
          android:inputType="numberDecimal"
          android:singleLine="true"
          android:maxLength="@integer/quantity_length" /&gt;
  </code></pre>
  
  <p>As its length is going to be used not only in the UI xml file but also in a java class and maybe some other places, I want to avoid problems when I update this value in future, so I want to put the length centralized in the dimens.xml resource file as follows:</p>
  
  <p><strong>dimens.xml</strong></p>
  
  <pre><code>&lt;resources&gt;
  
      &lt;!-- other things --&gt;
  
      &lt;!-- Constants --&gt;
      &lt;item name="quantity_length" format="integer" type="integer"&gt;10&lt;/item&gt;
  
      &lt;!-- other things --&gt;
  
  &lt;/resources&gt;
  </code></pre>
  
  <p>From a java class I need to read this value so I perform:</p>
  
  <pre><code>    TypedValue typedValue = new TypedValue();
      this.getResources().getValue(R.integer.quantity_length, typedValue, true);
  </code></pre>
  
  <p>but I can notice that there is no method getInt(), only getFloat():</p>
  
  <pre><code>    int digitsBefore = typedValue.getFloat();
  </code></pre>
  
  <p>so as I need to get it as integer.... how to do this? Of course, maybe I can get it using getFloat() and then casting to integer.... but I do not know if it is an elegant way to do it... so any ideas?</p>
  
  <p>UPDATE:
  Oooppssss I did a mistake. It is:
      int quantity = typedValue.getFloat();</p>
  
  <p>instead of:</p>
  
  <pre><code>int digitsBefore = typedValue.getFloat();
  </code></pre>