Giter VIP home page Giter VIP logo

compoundbuttongroup's Introduction

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.

compoundbuttongroup's People

Contributors

llollox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

compoundbuttongroup's Issues

How to add values international mode

interesting component, but if you have an application with more languages, as you can add entries to their will translate, but without changing internal value

label/value
house=>house
casa=>house

if you find it interesting, could allow entering optimal HashMap
HashMap<String,String>

Disable checkbox position

Is possible to disable the checkbox passing position by parameter ?

I have 5 checkbox , but if i want the user can check just 3, in the 4 checkbox he cant check.

have some method ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.