Edittext library by which you can easily achieve a lot of functionalities by directly implementing some lines of code in XML and on the Java side. The following are the functions that EditTextPicker provides:
- Empty checking
- Masking Edittext
- Pattern checking
- Range checking
Please see the description of this library in my article Edittext Picker Library
In project.gradle add this code it in root build.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Now, add the dependency in app.gradle:
dependencies {
implementation 'com.github.AliAzaz:Edittext-Library:X.X.X'
}
Note: By default required is true. But if you don't want to validate specific edittext then simply set it to false: app:required="false"
-- Required Edittext
<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtBoxReq"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:required="true" />
-- Range (5-10) with a default value of 999
<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtBoxRange"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
app:defaultValue="999"
app:maxValue="10"
app:minValue="5"
app:required="true"
app:type="range" />
-- Masking
<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtMask"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
app:mask="##-##-####"
app:required="false" />
-- Pattern with default value checking [Following pattern is: (2-4)Characters with (3-5)Digits ]
<com.edittextpicker.aliazaz.EditTextPicker
android:id="@+id/txtBoxDefault"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:defaultValue="null"
app:pattern="[^0-9]{2,4}[0-9]{3,5}"
app:required="true"
app:type="equal" />
Implement this code in submit button click
--- For Required component
if (!txtBoxReq.isEmptyTextBox()) return;
-- For validating range component
if (!txtBoxRange.isRangeTextValidate()) return;
-- For validating pattern component
if (!txtBoxDefault.isTextEqualToPattern()) return;
This library also support chain request
txtPicker = EditTextPicker(this,
EditTextPickerBuilder().apply {
setRequired(true)
setRangeValues(0.5f, 40.0f)
setMask("##.##")
setPattern("^(\\d{2,2}\\.\\d{2,2})$")
}.build())
.apply {
hint = "##.##"
inputType = InputType.TYPE_CLASS_NUMBER
}
Users can easily set the attribute values at runtime.
txtDate.setMask("##-##-####").setRequired(false)
edittextpicker = 2.1.1
gradle = 7.4.2
kotlin = 1.8.0
build_version = 34.0.0
min_api_level = 21
max_api_level = 34
Distributed under the MIT license. See LICENSE information.