An library easy-to-use of required fields in Android, this library validate the most important native Gui components of Android.
This library supports these components:
- EditText
- Spinner
- RadioButton
- CheckBox
- Switch
- ToggleButton
- RatingBar
- ImageView
- SeekBar
- ProgressBar
- It requires 14+ API.
- The compile version is API 23.
use git (sourcetree or others)
git clone https://github.com/fabian7593/MagicalRequiredFields.git
Download from Here
Another type download by Bintray from
And you can add the jcenter bintray library in dependecies, like this:
compile 'com.frosquivel:magicalrequiredfields:4.0'
If you need to validate the components like a "required fields" this library is the heaven for you :D.
You only need to download this example, or import the libraries in yoour project, but if you prefer it for fastest and easier add library to your project, you can use the gradle dependency, you have to add these lines in your build.gradle file:
repositories {
....
jcenter()
}
dependencies {
....
compile 'com.frosquivel:magicalrequiredfields:4.0'
}
You only need to import the library for use this.
The method of the library return false if any component have empty value or not pass the validate.
####For example:
If your have a EditText and you validate it, with this library,and you not entry any value, the method return false, but if you entry any value the method return true.
####Description Example
This example have some of the components that's the app supports. In this time are
*EditText
*Spinner
*RadioButton
*CheckBox
####Code Implementation
This is only for example, you need to fill the spinner with another form.
The spinner is fill with this values in the string.xml
<string-array name="planets_array">
<item> </item>
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
<item>Jupiter</item>
<item>Saturn</item>
<item>Uranus</item>
<item>Neptune</item>
</string-array>
You need to import the library
import com.frosquivel.magicalrequiredfields.MagicalRequiredFields;
The method of this example is static and you not have to create the instance of this.
You need to pass as parameters the list of your views to validate, and the message if you need to show in the set error message.
```bash List listObj = new ArrayList(); listObj.add(yourEditText); listObj.add(yourSpinner);
Boolean validateFields =
MagicalRequiredFields.validateReq(listObj,"This is an required field");
if(validateFields){
Toast.makeText(getApplicationContext(), "You passed the test", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), "You don't passed the test", Toast.LENGTH_SHORT).show();
}
<br>
In the case of check box and radio button you need to group this for validate in group and not in individual form.
You need to pass the list of your vies and a list of lists of views like this:
```bash
List<View> listObj = new ArrayList<View>();
listObj.add(yourEditText);
listObj.add(yourSpinner);
List<View> listObjRadioGroup = new ArrayList<View>();
listObjRadioGroup.add(radio1);
listObjRadioGroup.add(radio2);
List<View> listObjCheckBoxGroup = new ArrayList<View>();
listObjCheckBoxGroup.add(checkBox1);
listObjCheckBoxGroup.add(checkBox2);
List<List<View>> listOfListViewsGroup = new ArrayList<List<View>>();
listOfListViewsGroup.add(listObjRadioGroup);
listOfListViewsGroup.add(listObjCheckBoxGroup);
Boolean validateFields =
MagicalRequiredFields.validateReq(listObj,listOfListViewsGroup,"This is an required field");
if(validateFields){
Toast.makeText(getApplicationContext(), "You passed the test", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), "You don't passed the test", Toast.LENGTH_SHORT).show();
}
}
});
##Documentation
All the code has a internal documentation for more explanation of this example.
Source code can be found on github
Licenced under APACHE 2.0.
Developed by Fabian Rosales
Known as Frosquivel Developer
Web Page www.frosquivel.com
Blog (Spanish) www.frosquivel.com/blog