项目作者: Theophrast

项目描述 :
Android EditText extension for validate numeric inputs
高级语言: Java
项目地址: git://github.com/Theophrast/NumericInputEditText.git
创建时间: 2017-04-30T11:26:36Z
项目社区:https://github.com/Theophrast/NumericInputEditText

开源协议:

下载


NumericInputEdittext

Android EditText extension for validate numeric input values.

This library contains four main UI element :

  • IntegerInputEdittext
    for integer input, set interval e.g. [ 0 , 100 ]

  • LongInputEdittext
    for long input, set interval e.g. [ 50000l , 150000l ]

  • FloatInputEditText
    for float value input, set interval e.g. ] 0f , 100f ]

  • DoubleInputEdittext
    for double value input, set interval e.g. ] 0d , 1000000000d ]


Features

  • Set interval for valid numeric input from attribute string.
  • Get value directly from EditText with one line
  • Validate with one line
  • Autocorrect the values

demo1


How to use

Set the interval:

  1. IntegerInputEditText et_Int = (IntegerInputEditText) findViewById(R.id.et_intinput);
  2. et_Int.setValidInterval("[0,50]")

Validate, show error messages, and autocorrect the wrong value:

  1. et_Int.setAutoCorrectOnError(true);
  2. et_Int.setShowMessageOnError(true);
  3. boolean isInputValueValid = et_Int.isValid();

Get value directly from Edittext:

  1. Integer result = et_Int.getValue();

You can also specify the parameters from layout:

  1. <com.theophrast.forgivingui.numericinputedittext.ui.IntegerInputEditText
  2. xmlns:numericinput="http://schemas.android.com/apk/res-auto"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:id="@+id/et_intinput"
  6. numericinput:show_message_on_error="true"
  7. numericinput:autocorrect_on_error="true"
  8. numericinput:valid_range="[0,100]"
  9. ></com.theophrast.forgivingui.numericinputedittext.ui.IntegerInputEditText>

To float value input use this:

  1. <com.theophrast.forgivingui.numericinputedittext.ui.FloatInputEditText
  2. xmlns:numericinput="http://schemas.android.com/apk/res-auto"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:id="@+id/et_floatinput"
  6. numericinput:show_message_on_error="true"
  7. numericinput:autocorrect_on_error="true"
  8. numericinput:correction="0.1"
  9. numericinput:valid_range="]0f,1f]"
  10. ></com.theophrast.forgivingui.numericinputedittext.ui.FloatInputEditText>

Check the sample for more details.

Gradle

  1. dependencies{
  2. ...
  3. compile 'com.theophrast.forgivingui.numericinputedittext:numericinputedittext:1.0.2'
  4. }

Interval set

The valid interval of a NumericInputEditText can be specified with a String.
Use [valueMin , valueMax ] brackets to include the endpoints of the interval,
or use ]valueMin , valueMax[ brackets to exclude them.
You can also combine the brackets.
Examples:
>
[ minimum_enabled_value , maximum_enabled_value ]
or
] minimum_not_enabled_value , maximum_not_enabled_value [
or
] minimum_not_enabled_value , maximum_enabled_value ]
or
[ minimum_enabled_value , maximum_not_enabled_value [

Examples for interval set

Input interval for Dice rolling (int):

Enabled values are 1, 2, 3, 4, 5 and 6.

  1. String interval = "[1,6]"

from layout.xml:

  1. numericinput:valid_range="[0,100]"
Input interval for a material temperature in laboratory (float - °C):

Enabled values are from ‒273,15f to positive infinite

  1. String interval = "[‒273,15f,+["
Input interval for measured length (float):

In this case the enabled values are positive float numbers without maximum limit, but

0f value is not enabled.

  1. String interval = "]0,+["

License

  1. Copyright 2017 Janos Jakub
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.