I am applying input filter on edittext with below conditions
- The input of edit text should accept numberDecimal which is defined in xml (working)
- first digit of input should not be "." (dot) like ".9" (working)
- edit text can have "." after first digit like "1.9" (working)
- maximum length is 6 (not working)
but in this case only .(dot) filter is working, not maximum length. Please help how to make it work. I tried reverse filter setting like first dot and then maximum Length, but nothing works!
edt.setFilters(new InputFilter[]{new InputFilter.LengthFilter(6), ignoreFirstDot()});
// ignore first input as dot on edit text
public static InputFilter ignoreFirstDot() {
return new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
for (int i = start; i < end; i++) {
if (source.toString().startsWith(".")) {
if (dstart == 0)
return "";
}
}
return null;
}
};
}
Here is my Edit Text from XML. even though defined in xml as maxLength =6, but still not working
<EditText
android:id="@+id/edt"
android:layout_width="0dp"
android:layout_height="@dimen/margin45"
android:layout_weight=".5"
android:background="@drawable/edit_border_square"
android:inputType="numberDecimal"
android:lines="1"
android:maxLength="6"
android:maxLines="1"
android:padding="5dp"
android:singleLine="true"
android:textColor="@color/black"
android:textCursorDrawable="@drawable/color_cursor"
android:textSize="@dimen/text11" />