Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mauker1/freeradiogroup

FreeRadioGroup is an Android library that allows grouping radio buttons without constraining them into a Linear Layout fashion, you can place the buttons anywhere you like.
https://github.com/mauker1/freeradiogroup

Last synced: 9 days ago
JSON representation

FreeRadioGroup is an Android library that allows grouping radio buttons without constraining them into a Linear Layout fashion, you can place the buttons anywhere you like.

Awesome Lists containing this project

README

        

# FreeRadioGroup

FreeRadioGroup is an Android library that allows grouping radio buttons without constraining them into a Linear Layout fashion, you can place the buttons anywhere you like.

[ ![Download](https://api.bintray.com/packages/mauker/maven/FreeRadioGroup/images/download.svg) ](https://bintray.com/mauker/maven/FreeRadioGroup/_latestVersion)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/Mauker1/FreeRadioGroup/blob/main/LICENSE)
![APK size](https://img.shields.io/badge/Size-42KB-e91e63.svg)

Buy Me a Coffee at ko-fi.com

# Download

To add `FreeRadioGroup` to your project add the following gradle dependency:

```kotlin
implementation 'br.com.mauker:freeradiogroup:1.0.1'
```

Also make sure to have `jcenter()` in your gradle repositories.

# Usage

To use `FreeRadioGroup` add the following code in the same XML layout as your Radio Buttons:

```xml

```

## Breaking down the properties

- The first and most important attribute is `app:referenced_ids`. Use it to add radio buttons to this group by adding their IDs;
- The `app:checkedRadioButton` attribute will define which radio button from this group should be checked by default;
- As of `V_1.0.0` if you're adding `FreeRadioGroup` inside a constraint layout, it's necessary to add the `tools:ignore="MissingConstraints"` to safely ignore the missing constraints error message.

*Note:* Since `FreeRadioGroup` has no width or height, you can use either `wrap_content` or `0dp`.

# Using the group in your Kotlin (or Java) code

To use `FreeRadioGroup` inside your code, simply use `findViewById()` to get its reference.

```kotlin
val group: FreeRadioGroup = findViewById(R.id.radioGroup)
```

## Checking and clearing programmatically

You can either check an individual radio button from a group or clear the selection using the following methods:

- `group.check(radioButtonId: Int)` to check a the radio button from this group;
- `group.clearCheck()` to clear the current selection.

## Getting the current selection

You can get the selected radio button by using the `group.getCheckedRadioButtonId()` method. It'll return the radio button ID or `View.NO_ID` if there's no selection.

## Setting up the checked listener

It's also possible to listen for changes in selection by using the `OnCheckedChangeListener` interface.

```kotlin
group.setOnCheckedChangeListener(object: OnCheckedChangeListener {
override fun onCheckedChanged(group: FreeRadioGroup, checkedId: Int) {
// Do something with the selection
}
})
```