Giter Site home page Giter Site logo

radiogroupplus's Introduction

RadioGroupPlus

This is a tweak to the original Android RadioGroup.java class. This is because the original RadioGroup is only able to do:

And it is not able to do this:

*Note: this image is stolen shamelessly from this Stackoverflow post: http://stackoverflow.com/questions/20456322/preparing-customized-radio-group-type-of-layout

With RadioGroupPlus, you can do this:

Doc

Everything should function the same as the original RadioGroup, so refer to this: http://developer.android.com/reference/android/widget/RadioGroup.html

Demo

Refer to app/ folder of this repo.

Usage

Simple example:

   <worker8.com.github.radiogroupplus.RadioGroupPlus
        android:id="@+id/radio_group_plus"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <LinearLayout...>
           <ImageView...>
           <TextView...>
           <RadioButton...>
        </LinearLayout>
        <LinearLayout...>
           <ImageView...>
           <TextView...>
           <RadioButton...>
        </LinearLayout>
        <LinearLayout...>
           <ImageView...>
           <TextView...>
           <RadioButton...>
        </LinearLayout>
   </worker8.com.github.radiogroupplus.RadioGroupPlus>

Explanation: the 3 RadioButton shown in the code above will be linked together by RadioGroupPlus automatically.


If you want a even weirder layout, it will also work, for example:

<worker8.com.github.radiogroupplus.RadioGroupPlus
    android:id="@+id/radio_group_plus"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <LinearLayout...>
       <ImageView...>
       <TextView...>
       <RadioButton...>
    </LinearLayout>
    <LinearLayout...>
       <ImageView...>
       <TextView...>
       <RadioButton...>
    </LinearLayout>
    <LinearLayout...>
      <RelativeLayout>
         <ImageView...>
         <TextView...>
         <RadioButton...>
      </RelativeLayout>
      <RelativeLayout>
         <ImageView...>
         <TextView...>
         <RadioButton...>
      </RelativeLayout>
    </LinearLayout>
</worker8.com.github.radiogroupplus.RadioGroupPlus>

Now the 2 RadioButton under the LinearLayout and the 2 RadioButton inside the RelativeLayout will all be linked together.

In fact, there is no limitation to what the layout should look like, because RadioGroupPlus will just look for all the RadioButton in it's children and link them together.

How it works / Contribute

You don't actually need to read this part unless you are interested or you want to contribute or fix this repo. I wrote a simple TreeTraversel to traverse all the children that will be added to RadioGroupPlus, a Pre-order traversal is used but there is no special reason of why because it doesn't really matter in this case.

While traversing, the listener mChildOnCheckedChangeListener is added to the RadioButton, so when the RadioButton is clicked, mChildOnCheckedChangeListener will be called, and CheckedStateTracker#onCheckedChanged will be called to properly toggle the RadioButtons.

In short, look for traverseTree() in if you want to make changes.

Download/Install

Add this to top level build.gradle:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

Add this under dependencies:

compile 'com.github.worker8:RadioGroupPlus:v1.0.1'

If you run into conflict, use this instead:

compile('com.github.worker8:RadioGroupPlus:v1.0.1') {
    transitive = false;
}

The MIT License (MIT)

Copyright 2015 Tan Jun Rong

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

radiogroupplus's People

Contributors

worker8 avatar

Watchers

das_vicky avatar

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.