I have an EditText which is decimal and I set its length using android:maxLength property in xml:
With your example, why don't you use this method?
XML
<integer name="quantity_length">10</integer>
JAVA
getResources().getInteger(R.integer.quantity_length);
Why not store the integer in res/integers.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="quantity_length">12</integer>
</resources>
And to access the values in code
int myInteger = getResources().getInteger(R.integer.quantity_length);
Or in XML
android:maxLength="@integer/quantity_length"
You dont need a TypedValue
use the following
(int) this.getResources().getDimension(R.integer.quantity_length)
;
Use:
Integer.ParseInt(digitsBefore);
I tested with Android Studio 3.3.1 with SDK lollipop
Keep an eye on the paths...
Clean and build... I had a pretty hard time, thinking it's not working, but after deleting the file and Re-add, and few clean and build, I got it working strange...
1. This works ( note the tick and its path)
2. Here is proof
int max = getContext().getResources().getInteger(R.integer.quantity_length);