I would like to see the maxLength
of an EditText
at run time to be able to make a text display decision.
Is that possible?
Here is a description of what I wan't to do.
I have a ListView with many rows and each row have an EditText and a TextView.
I've made a subclass of ArrayAdapter to be able to feed the String that I want to place in the EditText of each row.
I have set android:maxLength="12"
in the XML file.
I want to display a number in that EditText field, but if the number I want to display has more than android:maxLength="12"
I want to display an "error message" instead.
And I would prefer not to hard code that 12 in my subclass of ArrayAdapter.
There is probably a simple solution, but I haven't found it yet.
(android first time...)
If you want your disabled EditText to look the same as your enabled one, you should use android:enabled="false" in combination with android:textColor="..." . Show activity on this post. Used this if you have an icon to be clickable, this works for me.
use an input filter to limit the max length of a text view. This is very useful if someone already made some InputFilter . It overrides android:maxlength in xml file, so we need to add LengthFilter this way.
Only limited parameters have their getters, so I don't think you can read it .
So write length (Say 12) in values folder and use it in xml layout and arrayAdapter . Now its not hard-coded .
1)Create integer.xml in values *
<?xml version="1.0" encoding="utf-8"?> <resources> <item type="integer" name="max_length">12</item> </resources>
2)In layout
<TextView android:id="@+id/tv" android:layout_width="fill_parent" android:layout_height="wrap_content" android:maxLength="@integer/max_length" />
3) in ArrayAdapter :
int maxLength = getResources().getInteger(R.integer.max_length);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With