Skip to content

Repository files navigation

Compound Button Group Android

Alt textAPIAndroid Arsenal

An Android library to easily implement compound buttons

Installation

Gradle

Add Gradle dependency:

dependencies {
compile 'com.llollox.androidprojects:compoundbuttongroup:1.0.2'
}

Maven

<dependency>
<groupId>com.llollox.androidprojects</groupId>
<artifactId>compoundbuttongroup</artifactId>
<version>1.0.2</version>
<type>pom</type>
</dependency>

Usage

Check Box

Sample of check_box

<com.llollox.androidprojects.compoundbuttongroup.CompoundButtonGroup
android:layout_width="match_parent"android:layout_height="wrap_content"app:entries="@array/planets"app:compoundType="check_box"/>

Check Box Grid (2 Cols, Label After)

Sample of check_box

<com.llollox.androidprojects.compoundbuttongroup.CompoundButtonGroup
android:layout_width="match_parent"android:layout_height="wrap_content"app:entries="@array/planets"app:compoundType="check_box"app:numCols="2"app:labelOrder="after"/>

Radio

Sample of radio

<com.llollox.androidprojects.compoundbuttongroup.CompoundButtonGroup
android:layout_width="match_parent"android:layout_height="wrap_content"app:entries="@array/planets"app:compoundType="radio"app:labelOrder="after"/>

Radio Grid (3 Cols)

Sample of check_box

<com.llollox.androidprojects.compoundbuttongroup.CompoundButtonGroup
android:layout_width="match_parent"android:layout_height="wrap_content"app:entries="@array/planets"app:compoundType="radio"app:numCols="3"app:labelOrder="after"/>

Getters

  • List<Integer> getCheckedPositions() Returns the current checked positions
List<Integer> positions = compoundButtonGroup.getCheckedPositions();
  • CompoundType getCompoundType() Get the type of the compound buttons.
compoundButtonGroup.getCompoundType();
  • LabelOrder getLabelOrder() Get the label order of the compound buttons. This determines if the label is before or after the compound button.
compoundButtonGroup.getLabelOrder();
  • int getNumCols() Get the current number of cols.
compoundButtonGroup.getNumCols();

Setters

  • void setCheckedPosition(int position) Checks the button at the position passed as argument. Typically to be used with radio buttons.
intposition = 3;
compoundButtonGroup.setCheckedPosition(position);
  • void setCheckedPositions(List<Integer> positions) Checks all the buttons at the positions passed as argument. Typically to be used with check box buttons.
List<Integer> positions = newArrayList<Integer>(){{add(2); add(4);}};
compoundButtonGroup.setCheckedPositions(positions);
  • void setCompoundType(CompoundType compoundType) Set the type of the compound buttons. Allowed values are: CompoundType.CHECK_BOX, CompoundType.RADIO. In order to see the changes on UI please call the reDraw() method.
compoundButtonGroup.setCompoundType(CompoundButtonGroup.CompoundType.RADIO);
  • void setEntries(List<String> entries) Set the entries for the compound button group. In order to see the changes on UI please call the reDraw() method.
List<String> entries = newArrayList<String>(){{add("Mars"); add("Mercury"); add("Earth");}};
compoundButtonGroup.setEntries(entries);
  • void setEntries(HashMap<String, String> entries) Set the entries for the compound button group. The key / value pair represent the value / label of the entry respectively. In order to see the changes on UI please call the reDraw() method.
LinkedHashMap<String, String> map = newLinkedHashMap<>();
map.put("house", getString(R.string.house));
map.put("orange", getString(R.string.orange));
compoundButtonGroup.setEntries(map);
compoundButtonGroup.reDraw();
  • void setLabelOrder(LabelOrder LabelOrder) Set the label order of each compound button. This determines if the label is before or after the compound button. Allowed values are: LabelOrder.BEFORE, LabelOrder.AFTER. In order to see the changes on UI please call the reDraw() method.
compoundButtonGroup.setLabelOrder(CompoundButtonGroup.LabelOrder.AFTER);
  • void setNumCols(int numCols) Set the number of cols. If it is greater than 1 the compound buttons are shown as a grid. NB. It cannot be smaller than 1! In order to see the changes on UI please call the reDraw() method.
intnumCols = 2;
compoundButtonGroup.setNumCols(numCols);

Listeners

OnButtonSelectedListener
compoundButtonGroup.setOnButtonSelectedListener(newCompoundButtonGroup.OnButtonSelectedListener() {
@OverridepublicvoidonButtonSelected(intposition, Stringvalue, booleanisChecked) {
// Your code
}
});

Attributes

It is possible to customize the compound button group applying the following options:

Option NameFormatDescription
wapp:compoundTypecheck_box or radio
app:entriesarrayString array of the entries of the compound button group.
app:labelOrderbefore or afterThis determines if the label is before or after the compound button. By default is before.
app:numColsintSetting this parameter the compound buttons are shown as a grid and it indicates the number of cols of the grid.

About

An Android library to easily implement compound buttons

Topics

Resources

Stars

54 stars

Watchers

7 watching

Forks

Releases

Packages

Contributors

Languages