Skip to content

llollox/CompoundButtonGroup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0d0d8dc · May 28, 2017

History

21 Commits
May 2, 2017
May 2, 2017
Apr 29, 2017
Apr 27, 2017
Apr 30, 2017
Apr 27, 2017
May 28, 2017
Apr 27, 2017
Apr 27, 2017
Apr 27, 2017
Apr 27, 2017
Apr 27, 2017

Repository files navigation

Compound Button Group Android

Alt text API Android 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.
int position = 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 = new ArrayList<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 = new ArrayList<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 = new LinkedHashMap<>();
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.
int numCols = 2;
compoundButtonGroup.setNumCols(numCols);

Listeners

OnButtonSelectedListener
compoundButtonGroup.setOnButtonSelectedListener(new CompoundButtonGroup.OnButtonSelectedListener() {
    @Override
    public void onButtonSelected(int position, String value, boolean isChecked) {
        // Your code
    }
});

Attributes

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

Option Name Format Description
w app:compoundType check_box or radio
app:entries array String array of the entries of the compound button group.
app:labelOrder before or after This determines if the label is before or after the compound button. By default is before.
app:numCols int Setting this parameter the compound buttons are shown as a grid and it indicates the number of cols of the grid.

Releases

No releases published

Packages

No packages published

Languages