Android Multi Form Builder is a simple library to help you make simple form faster without create xml codes.
- Easily build forms with minimal effort
- Clonable builder as template. So you can make more element with a single builder object.
- More customable option such Text Font, Text Color, etc
In order to use the library, please follow this step bellow:
- Add the following to your project level
build.gradle
:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
- Add this to your app
build.gradle
:
dependencies {
implementation 'com.github.c0deslinger:android-java-multiformbuilder:1.0.3'
}
- Init your form layout:
Java:
LinearLayout formLayout = (LinearLayout)findViewById(R.id.formLayout);
Kotlin:
//pfft
- Make template view builder and set default value
Java:
MyEdittext.Builder edtBuilder = new MyEdittext.Builder(ExampleJavaActivity.this).setFormLayout(formLayout);
Kotlin:
val edtBuilder = MyEdittext.Builder(this@ExampleKotlinActivity).setFormLayout(formLayout)
- Create EditText + Search Button
Java:
MyEdittext edtId = edtBuilder.clone().setTitle("ID").setMode(MyEdittext.Mode.SEARCH).create();
edtId.setOnClickSearchListener(keyword -> toast("Search: "+keyword));
Kotlin:
var edtId = edtBuilder.clone().setTitle("ID").setMode(MyEdittext.Mode.SEARCH).create()
edtId.setOnClickSearchListener { keyword -> toast("Search: $keyword") }
- Create EditText
Java:
MyEdittext edtName = edtBuilder.clone().setTitle("Name").create();
Kotlin:
var edtName = edtBuilder.clone().setTitle("Name").create()
- Create EditText with 3 lines
Java:
MyEdittext edtAddress = edtBuilder.clone().setTitle("Address").setMinLines(3).create();
Kotlin:
var edtAddress = edtBuilder.clone().setTitle("Address").setMinLines(3).create()
- Create EditText + datepicker
Java:
MyEdittext edtBirthdate = edtBuilder.clone().setInputType(InputType.TYPE_CLASS_DATETIME)
.setTitle("Birthdate").setDateformat("dd-MM-yyyy")
.setTitleColorResource(R.color.dark_grey)
.create();
Kotlin:
var edtBirthdate = edtBuilder.clone().setInputType(InputType.TYPE_CLASS_DATETIME)
.setTitle("Birthdate").setDateformat("dd-MM-yyyy")
.setTitleColorResource(R.color.dark_grey)
.create()
- Create RadioButton
Java:
MyRadioButton rdbGender = new MyRadioButton.Builder(ExampleJavaActivity.this)
.setTitle("Gender").setOptionList(new String[]{"Male", "Female"})
.setFormLayout(formLayout).setSelected("Female").create();
Kotlin:
var rdbGender = MyRadioButton.Builder(this@ExampleKotlinActivity).setFormLayout(formLayout)
.setTitle("Gender").setOptionList(arrayOf("Male", "Female")).setSelected("Female").create()
Note: If you not define template builder on the beginning, you have to setFormLayout to attach view.
- Create multiple EditText in a single row
Java:
HashMap<String, MyEdittext> edtList = new LinkedHashMap<>();
MyEdittext.Builder edtItemBuilder = new MyEdittext.Builder(ExampleJavaActivity.this);
edtList.put("No", edtItemBuilder.clone().setTitle("No").setInputType(InputType.TYPE_CLASS_NUMBER).create());
edtList.put("Zip", edtItemBuilder.clone().setTitle("Zip").setInputType(InputType.TYPE_CLASS_NUMBER).create());
MyEdittextMultiple edtMultiple = new MyEdittextMultiple.Builder(ExampleJavaActivity.this, edtList)
.setFormLayout(formLayout).setMargin(50).create();
Kotlin:
var edtList = LinkedHashMap<String, MyEdittext>()
var edtItemBuilder = MyEdittext.Builder(this@ExampleKotlinActivity)
edtList.put("No", edtItemBuilder.clone().setTitle("No").setInputType(InputType.TYPE_CLASS_NUMBER).create())
edtList.put("Zip", edtItemBuilder.clone().setTitle("No").setInputType(InputType.TYPE_CLASS_NUMBER).create())
var edtMultiple = MyEdittextMultiple.Builder(this@ExampleKotlinActivity, edtList)
.setFormLayout(formLayout).setMargin(50).create()
- Create spinner view
Java:
ArrayList<String> cityList = new ArrayList<>();
cityList.add("Malang");
cityList.add("Surabaya");
MySpinner spinCity = new MySpinner.Builder(ExampleJavaActivity.this)
.setTitle("City").setItem(cityList).setDefaultSelected("Surabaya").setFormLayout(formLayout).create();
Kotlin:
val cityList = ArrayList<String>()
cityList.add("Malang")
cityList.add("Surabaya")
var spinCity = MySpinner.Builder(this@ExampleKotlinActivity)
.setTitle("City").setItem(cityList).setDefaultSelected("Surabaya").setFormLayout(formLayout).create()
- Create multiple checkbox
Java:
ArrayList<String> educationList = new ArrayList<>();
educationList.add("Associate");
educationList.add("Bachelor");
educationList.add("Master");
MyCheckbox myCheckboxView = new MyCheckbox.Builder(ExampleJavaActivity.this)
.setTitle("Education").setCheckBoxItem(educationList)
.setFormLayout(formLayout).setOnCheckedListener(selected -> toast("selected: "+selected)).create();
Kotlin
val educationList = ArrayList<String>()
educationList.add("Associate")
educationList.add("Bachelor")
educationList.add("Master")
val myCheckboxView = MyCheckbox.Builder(this@ExampleKotlinActivity)
.setTitle("Education").setCheckBoxItem(educationList)
.setFormLayout(formLayout).setOnCheckedListener{ selected -> toast("selected: $selected") }.create()
- Create TextView
Java:
MyTextView myTextView = new MyTextView.Builder(ExampleJavaActivity.this)
.setTitle("Note:").setTitleFont("fonts/Roboto-Bold.ttf")
.setContent("Please check again before submit").setFormLayout(formLayout).create();
Kotlin:
var myTextView = MyTextView.Builder(this@ExampleKotlinActivity)
.setTitle("Note:").setTitleFont("fonts/Roboto-Bold.ttf")
.setContent("Please check again before submit").setFormLayout(formLayout).create()
- Get values Java:
Button btnSubmit = (Button)findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(view -> toast("Name: " + edtName.getValue()
+ " Gender: " + rdbGender.getValue()
+ " Address: " + edtAddress.getValue()
+ " Birthdate: " + edtBirthdate.getValue()
+ " No: " + edtMultiple.getValue("No")
+ " Zip: " + edtMultiple.getValue("Zip")
+ " City: " + spinCity.getValue()
+ " Education: "+myCheckboxView.getAllChecked()));
Kotlin:
btnSubmit.setOnClickListener{ view -> toast("Name: " + edtName.getValue()
+ " Gender: " + rdbGender.getValue()
+ " Address: " + edtAddress.getValue()
+ " Birthdate: " + edtBirthdate.getValue()
+ " No: " + edtMultiple.getValue("No")
+ " Zip: " + edtMultiple.getValue("Zip")
+ " City: " + spinCity.getValue()
+ " Education: "+myCheckboxView.getAllChecked())}
Send Pull Requests and Let's rock n roll
This Library is released under the Apache License, Version 2.0