Skip to content

Repository files navigation

DynamicCheckBox - Easy CheckBox Dynamic


Simple way to use Dynamic CheckBox


Content List


Download

Add maven jitpack.io and dependencies in build.gradle (Project) :

// build.gradle projectallprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
// build.gradle app/moduledependencies {
...
implementation 'com.github.gzeinnumer:DynamicCheckBox:version'
}

Feature List


Usage

DynamicCheckBox

  • Widget on xml
<com.gzeinnumer.dc.DynamicCheckBox
android:id="@+id/dc"android:layout_width="match_parent"android:layout_height="wrap_content"/>

if you want to custom your CheckBox use app:style="@style/checkBoxStyle" on view, and make style on your res->value->style.xml

<resourcesxmlns:tools="http://schemas.android.com/tools">
<stylename="checkBoxStyle"parent="Base.Theme.AppCompat">
<itemname="android:textColor">#FFE500</item>
</style>
</resources>
<com.gzeinnumer.dc.DynamicCheckBox
...
app:orientationCheckBox="horizontal"app:style="@style/checkBoxStyle"/>

  • Content Item there is 2 type list that you can sent to this CheckBox.

Type 1

DynamicCheckBoxdynamicCheckBox = findViewById(R.id.dc);
ArrayList<String> listString = newArrayList<String>();
listString.add("Satu");
listString.add("Dua");
listString.add("Tiga");
listString.add("Empat");
dynamicCheckBox.setItemList(listString)
.setOnCheckedChangeListener(newDynamicCheckBox.OnCheckedChangeListener<String>() {
@OverridepublicvoidonCheckedChanged(ArrayList<String> items) {
for (inti=0; i<items.size(); i++){
Log.d(TAG, "onCheckedChanged: "+items.get(i));
}
}
@OverridepublicvoidonCheckedShow(StringclickedValue) {
Log.d(TAG, "onCheckedShow: "+clickedValue);
}
});

Type 2 for this type you should override function toString() in your model pojo

publicclassExampleModel {
privateintid;
privateStringname;
privateStringaddress;
//constructor//getter//setter@OverridepublicStringtoString() {
return"ExampleModel{" +
"id=" + id +
", name='" + name + '\'' +
", address='" + address + '\'' +
'}';
}
}

Use your own model and dont forget to declare your model pojo in onCallBack. Example DynamicCheckBox.OnCheckedChangeListener<ExampleModel>

DynamicCheckBoxdynamicCheckBox = findViewById(R.id.dc);
ArrayList<ExampleModel> listObject = newArrayList<>();
listObject.add(newExampleModel(1, "Zein", "Balbar"));
listObject.add(newExampleModel(2, "Zein2", "Balbar2"));
listObject.add(newExampleModel(3, "Zein3", "Balbar3"));
listObject.add(newExampleModel(4, "Zein4", "Balbar4"));
dynamicCheckBox.setItemList(listObject)
.setOnCheckedChangeListener(newDynamicCheckBox.OnCheckedChangeListener<ExampleModel>() {
@OverridepublicvoidonCheckedChanged(ArrayList<ExampleModel> items) {
for (inti=0; i<items.size(); i++){
Log.d(TAG, "onCheckedChanged: "+items.get(i).getName());
Log.d(TAG, "onCheckedChanged: "+items.get(i).getAddress());
}
}
@OverridepublicvoidonCheckedShow(StringclickedValue) {
Log.d(TAG, "onCheckedShow: "+clickedValue);
}
});

Set setSelectedItem(index) use before setItemList(list).

dynamicCheckBox.setSelectedItem(1,2,3).setItemList(list). ...
//ordynamicCheckBox.setSelectedItem(newArrayList<Integer>()).setItemList(list). ...

Preview :

Preview Single ObjectPreview Model Pojo
Output data Single Object
Output data Model Pojo

Example Code/App

FullCode MainActivity & ExampleModel & XML

Sample Code And App


Version

  • 1.0.3
    • First Release
  • 2.0.0
    • Support SDK 16
  • 2.0.1
    • Bug Fixing
  • 2.1.0
    • setSelectedItem()
  • 2.1.1
    • Bug Fixing
  • 2.1.2
    • Bug Fixing

Contribution

You can sent your constibution to branchopen-pull.


Copyright 2020 M. Fadli Zein

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages