Code Monkey home page Code Monkey logo

togglebuttongroup's Introduction

ToggleButtonGroup

API Android Arsenal

A container of toggle buttons, supports multiple / single selection and button customization.

Gradle

AndroidX:

dependencies {
    implementation 'com.nex3z:toggle-button-group:1.2.3'
}

AppCompact:

dependencies {
    implementation 'com.nex3z:toggle-button-group:1.1.9'
}

SingleSelectToggleGroup

You can create a group of single-select toggle buttons with SingleSelectToggleGroup.

<com.nex3z.togglebuttongroup.SingleSelectToggleGroup
    android:id="@+id/group_choices"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tbgCheckedButton="@+id/choice_a">

    <com.nex3z.togglebuttongroup.button.CircularToggle
        android:id="@+id/choice_a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="A"/>

    <com.nex3z.togglebuttongroup.button.CircularToggle
        android:id="@+id/choice_b"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="B"/>

       <!--...-->

</com.nex3z.togglebuttongroup.SingleSelectToggleGroup>

MultiSelectToggleGroup

You can create a group of multi-select toggle buttons with MultiSelectToggleGroup.

<com.nex3z.togglebuttongroup.MultiSelectToggleGroup
    android:id="@+id/group_weekdays"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tbgChildSpacing="auto">

    <com.nex3z.togglebuttongroup.button.CircularToggle
        android:id="@+id/sun"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="S"/>

    <com.nex3z.togglebuttongroup.button.CircularToggle
        android:id="@+id/mon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="M"/>

    <!--...-->

</com.nex3z.togglebuttongroup.MultiSelectToggleGroup>

Flow Buttons to Next Row

<com.nex3z.togglebuttongroup.MultiSelectToggleGroup
    android:id="@+id/group_dummy"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    app:tbgFlow="true"
    app:tbgChildSpacing="auto"
    app:tbgChildSpacingForLastRow="align"
    app:tbgRowSpacing="8dp">

    <!--...-->

</com.nex3z.togglebuttongroup.MultiSelectToggleGroup>

With tbgFlow attribute set to true, buttons are allowed to flow to next row when there is no enough space in current row. With tbgChildSpacing set to auto, buttons are evenly placed in each row.

Listeners

For SingleSelectToggleGroup, use OnCheckedChangeListener to listen to the change of the checked button. Use getCheckedId() to get the id of the checked button.

SingleSelectToggleGroup single = (SingleSelectToggleGroup) findViewById(R.id.group_choices);
single.setOnCheckedChangeListener(new SingleSelectToggleGroup.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(SingleSelectToggleGroup group, int checkedId) {

    }
});

For MultiSelectToggleGroup, use OnCheckedStateChangeListener to be notified of any changes in the group. Use getCheckedIds() to get the ids of all checked buttons.

MultiSelectToggleGroup multi = (MultiSelectToggleGroup) findViewById(R.id.group_weekdays);
multi.setOnCheckedChangeListener(new MultiSelectToggleGroup.OnCheckedStateChangeListener() {
    @Override
    public void onCheckedStateChanged(MultiSelectToggleGroup group, int checkedId, boolean isChecked) {

    }
});

Custom Button

You can implement custom toggle button in three ways,

CompoundButton implements Checkable interface, toggles itself when being clicked and provides listener for ToggleButtonGroup to keep track of its checked state. CompoundButton is basically a Button / TextView. You can add your custom style and behaviour to the button like CustomCompoundButton from the sample.

If you choose to implement ToggleButton, besides the Checkable interface, you also need to implement a setOnCheckedChangeListener(), which allows ToggleButtonGroup to listen to the changes of any checked states. You need to handle the click event on the button and toggle its checked state properly, as ToggleButtonGroup will not toggle the button when it's being clicked. CustomToggleButton from the sample is a simple toggle button implementing ToggleButton.

CompoundToggleButton implements ToggleButton and toggles its checked state when being clicked. All you need to do is to design the look and feel for the checked and unchecked state. CustomCompoundToggleButton from the sample extends CompoundToggleButton and uses a flipping animation for state transition as shown above.

For more detail, please check the sample.

Licence

Copyright 2018 nex3z

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

togglebuttongroup's People

Contributors

nex3z avatar patchett 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  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  avatar  avatar  avatar  avatar

togglebuttongroup's Issues

Setting text programmatically

Hello,
thanks for a great work with this library :)
One question - is it possible to set button text programmatically?
With regards,

androidx version

Hi, can you provide a jetpack version?
We already migrated and dont want to add dependency to pre androidx artefacts

Change LabelToggle background and border color for checked/unchecked state programmatically?

Hi @nex3z ,
Thanks for developing such a great library. I am using your library in my project, I would like to know how I can simply just use my own background and border color and everything else the same.
Currently i am doing something like this:

private void initMultiSelectToggleGroup() {
        MultiSelectToggleGroup interestsMultiSelectToggleGroup = findViewById(R.id.interests_multi_select_toggle_group);
        String[] interests = {"Photography", "Hiking", "Skiing"};
        for (String interest : interests) {
            LabelToggle toggle = new LabelToggle(this);
            toggle.setText(interest);
            toggle.setMarkerColor(R.color.colorPrimaryLight);
            interestsMultiSelectToggleGroup.addView(toggle);
        }
    }

But with this I am getting a greyish border and background color instead of my defined colorPrimaryLight.

PS: You mentioned that we can use our custom buttons, but just for changing the background and border color, I don't think creating a whole new custom button is a good idea, plus I (beginner) am confused on how I can create a custom button (Complete Steps to create a custom button) . Please help me with this

Thanks in advance.

get position of selected

I have a MultiSelectToggleGroup with all the days of the week as in the image, I need to check these days (if they beat the current day), but not to use the texts because it has repeated (SATURDAY and SUNDAY is "S"), how do I get the position of items checked? or another way to do it?

image

OnCheckedChangeListener not called on unselecting the selected item

I've have a SingleSelectToggleGroup which contains two toggle buttons. On touching the selected item again, it gets unselected, but the OnCheckedChangeListener is not called?

It get called called when selected for the first time or when I toggle selection but not when unselecting a selected item

I need it to be called for my requirements or even simply disable unsecting when touched again (allow toggle select other buttons)

I hope understood my issue. Please reply

'checkedId' in onCheckedChanged()

I have problem with checkedID when setting setOnCheckedChangeListener() checkedID does not resets after activity has finished and reopened once again checkedID grows

get the string

how do i define the selected text on string like:

SingleSelectToggleGroup nominal = (SingleSelectToggleGroup) findViewById(R.id.nominal);

i've tried
String choosennominal = nominal.getCheckedPositions().toString();
and
String choosennominal = nominal.getTextButtons().toString();

but i still don't get the button text, help me please

Circular Background size and text color

Hello,

I’m using the SingleSelectToggleGroup and I tried to change the text color from black to another, the android: textColor= “”. Worked but when I click on one of the buttons the color do not change to white.

Also one of the buttons text is kind of long length (“women”) when I click on it the circle background doesn’t fit the entire word. I tried to set the length of height and width but nothing changed.

Waiting for your help and thank you so much for the grate library 🌷

Android 9 Error

The library encounter error with android 9

Fatal Exception: java.lang.IllegalArgumentException: Invalid Region.Op - only INTERSECT and DIFFERENCE are allowed at android.graphics.Canvas.checkValidClipOp(Canvas.java:779) at android.graphics.Canvas.clipPath(Canvas.java:1007) at co.ceryle.radiorealbutton.RoundedCornerLayout.dispatchDraw(RoundedCornerLayout.java:80) at android.view.View.buildDrawingCacheImpl(View.java:21122) at android.view.View.buildDrawingCache(View.java:20988) at android.view.View.draw(View.java:21577) at android.view.ViewGroup.drawChild(ViewGroup.java:4546) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4321) at android.view.View.updateDisplayListIfDirty(View.java:20718) at android.view.View.draw(View.java:21585) at android.view.ViewGroup.drawChild(ViewGroup.java:4546) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4321) at android.view.View.updateDisplayListIfDirty(View.java:20718) at android.view.View.draw(View.java:21585) at android.view.ViewGroup.drawChild(ViewGroup.java:4546) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4321) at android.view.View.updateDisplayListIfDirty(View.java:20718) at android.view.View.draw(View.java:21585) at android.view.ViewGroup.drawChild(ViewGroup.java:4546) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4321) at android.view.View.updateDisplayListIfDirty(View.java:20718) at android.view.View.draw(View.java:21585) at android.view.ViewGroup.drawChild(ViewGroup.java:4546) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4321) at android.view.View.updateDisplayListIfDirty(View.java:20718) at android.view.View.draw(View.java:21585) at android.view.ViewGroup.drawChild(ViewGroup.java:4546) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4321) at android.view.View.draw(View.java:21862) at android.widget.ScrollView.draw(ScrollView.java:2768) at android.view.View.updateDisplayListIfDirty(View.java:20732) at android.view.View.draw(View.java:21585) at android.view.ViewGroup.drawChild(ViewGroup.java:4546) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4321) at android.support.constraint.ConstraintLayout.dispatchDraw(ConstraintLayout.java:2023) at android.view.View.updateDisplayListIfDirty(View.java:20718) at android.view.View.draw(View.java:21585) at android.view.ViewGroup.drawChild(ViewGroup.java:4546) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4321) at android.view.View.updateDisplayListIfDirty(View.java:20718) at android.view.View.draw(View.java:21585) at android.view.ViewGroup.drawChild(ViewGroup.java:4546) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4321) at android.view.View.updateDisplayListIfDirty(View.java:20718) at android.view.View.draw(View.java:21585) at android.view.ViewGroup.drawChild(ViewGroup.java:4546) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4321) at android.view.View.updateDisplayListIfDirty(View.java:20718) at android.view.View.draw(View.java:21585) at android.view.ViewGroup.drawChild(ViewGroup.java:4546) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4321) at android.view.View.updateDisplayListIfDirty(View.java:20718) at android.view.View.draw(View.java:21585) at android.view.ViewGroup.drawChild(ViewGroup.java:4546) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4321) at android.view.View.draw(View.java:21862) at com.android.internal.policy.DecorView.draw(DecorView.java:1083) at android.view.View.updateDisplayListIfDirty(View.java:20732) at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:725) at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:731) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:840) at android.view.ViewRootImpl.draw(ViewRootImpl.java:3909) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3683) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2991) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1850) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8455) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949) at android.view.Choreographer.doCallbacks(Choreographer.java:761) at android.view.Choreographer.doFrame(Choreographer.java:696) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:6981) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)

How can I change the text padding of MultiSelectToggleGroup?

Default vertical padding inside MultiSelectToggleGroup seems way too high when textSize is small. And the class seems to offer no accessible function to alter it.

Edit: I believe I shall decrease the corner radius of the drawable of label buttons, and this seems not possible without recompiling the sources. Text padding can be altered with getTextView().setPadding() but this can only alter the padding above a lower bound determined by the corner radius of button.

怎么禁用点击事件

怎么禁用点击事件?默认选定好之后不能点击。

multiSelect.setEnabled(false);
multiSelect.setSelected(false);
multiSelect.setClickable(false);

都不好使

onCheckedChanged called twice

Playing around to find out if your lib is good to use for me, i found out that onCheckedChanged is called twice if i set check in code

single = findViewById(R.id.group_choices);
single.setOnCheckedChangeListener(new SingleSelectToggleGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(SingleSelectToggleGroup group, int checkedId) {
            Timber.i("%d",checkedId);
        }
});
single.check(R.id.choice_a);

get text in cicrularToggle

In a file xml I put text for each one single so how does the contents of the text in the selected file give me the programmatically

get Text

How to get the text of a clicked view

Position

I cannot get the selected button position, I am using flow label to create dynamic buttons from a string array as you written in your sample. How do I get the position of the button that is selected.
I tried to get the id of the button thought it would be sequential starting from 1, but it starts randomly.
I need to know whether first or last button or which button the user selected ?

Get the specific item position

First operation, it showed a true position, ex : 1, 2, 3, 4, 5, 6, 7. But the next operation it showed a wrong position, ex : 8, 9, 10, 11, 12, 13, 14. And after I closed the app, then I opened it again, it was added by 7, ex : 15, 16, 17, 18, 19, 20, 21. The first number always added by 7 after restarting app. But after I forced stop the app and then open it again, it showed a true position again.

Removing border color of LabelToggle?

Hey, great library!
I couldn't find an option to remove the border from LabelToggle.
CircularToggle seems to have it in default but I prefer the LabelToggle, due to its shape.
Any help is appreciated.

MultiSelectToggleGroup with Minimum Select Count

With using a MultiSelectToggleGroup, we can set a maximum select count with setMaxSelectCount but we can't "setMinSelectCount".

I tried to force the re-check of a LabelToggle in the OnCheckedChangeListener, and it doesn't update the UI of the MultiSelectToggleGroup but if using the getCheck of LabelToggle, it's state as changed.

hi

hi
how change item selected text color from label toggle?

Question: Multiple Rows?

Is it possible to arrange a group of toggle buttons in multiple rows and columns, sort of like

image

NullPointer Exception on Initialization

I have a simple app that is trying to do some drawing on the screen. Currently, I have it where I can touch the screen to place a circle on the screen.

I feel like this should be a simple fix for me to figure out, but I'm not sure if it's from the library or not. I'm kind of new to Android development. I'm getting an error saying
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.nex3z.togglebuttongroup.SingleSelectToggleGroup.setOnCheckedChangeListener(com.nex3z.togglebuttongroup.SingleSelectToggleGroup$OnCheckedChangeListener)' on a null object reference . This is happening when I try and find by the id the ToggleButton view in MyCanvas. I also tried moving the init() function to my MainActivity after setContentView with the same result.

Am I missing something super simple that would be causing this error?

Thanks.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="drawing.MainActivity">

    <com.nex3z.togglebuttongroup.SingleSelectToggleGroup
        android:id="@+id/group_choices"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tbgCheckedButton="@+id/choice_a">

        <com.nex3z.togglebuttongroup.button.CircularToggle
            android:id="@+id/choice_a"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="16sp"
            android:text="@string/choice_1"/>

        <com.nex3z.togglebuttongroup.button.CircularToggle
            android:id="@+id/choice_b"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="16sp"
            android:text="@string/choice_1"/>

        <com.nex3z.togglebuttongroup.button.CircularToggle
            android:id="@+id/choice_c"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="16sp"
            android:text="@string/choice_1"/>

        <com.nex3z.togglebuttongroup.button.CircularToggle
            android:id="@+id/choice_d"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="16sp"
            android:text="@string/choice_1"/>

    </com.nex3z.togglebuttongroup.SingleSelectToggleGroup>
</LinearLayout>

MainActivity

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    MyCanvas canvas;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        canvas = new MyCanvas(this);
        setContentView(canvas);
    }

}

MyCanvas

import android.content.Context;

import android.view.MotionEvent;
import android.view.View;
import android.graphics.Canvas;

import com.nex3z.togglebuttongroup.SingleSelectToggleGroup;

import java.util.ArrayList;
import java.util.List;

public class MyCanvas extends View {
    Graphics graphics;
    List<Shape> shapes;

    public MyCanvas(Context context) {
        super(context);
        init();
        graphics = new Graphics();
        shapes = new ArrayList<>();
    }

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        graphics.setCanvas(canvas);
        for (Shape shape : shapes) {
            try {
                shape.render(graphics, 0, 0);
            } catch (ShapeException e) {
                e.printStackTrace();
            }
        }
        invalidate();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                int x = (int) event.getX();
                int y = (int) event.getY();
                try {
                    makeShape(x, y);
                } catch (ShapeException e) {
                    e.printStackTrace();
                }
                invalidate();

            case MotionEvent.ACTION_MOVE:
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL: {
                break;
            }
        }
        invalidate();
        return true;
    }

    public void makeShape(int x, int y) throws ShapeException{
        Point p = new Point(x, y);
        Shape shape = new Circle(p, 50, 50);
        shapes.add(shape);
    }

    private void init() {
        SingleSelectToggleGroup single = findViewById(R.id.group_choices);
        single.setOnCheckedChangeListener(new SingleSelectToggleGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SingleSelectToggleGroup group, int checkedId) {
                System.out.println("Changed");
//                Log.v(LOG_TAG, "onCheckedChanged(): checkedId = " + checkedId);
            }
        });
    }
}

Method setbuttons don't exist

I need to get the text from the SingleSelectToggleGroup and was following this issue closed #3 but the setbuttons method does not exist, is there any other way to get the text? because from what I saw, the id always changes.

old attributes

How can I set these attributes programmatically? because I'm still using the old version and trying to update the button.

app:tbgButtonTextPaddingLeft="16dp"
app:tbgButtonTextPaddingRight="16dp"

Because when I try to use toggle.setBackground(getResources().getDrawable(R.drawable.round_rect_button_bg)); toggle.setPadding(16,0,16,0);

Then it becomes like this:
screenshot_20180128-124148 1

My layout

            <com.nex3z.togglebuttongroup.SingleSelectToggleGroup
                app:paddingEnd="20dp"
                app:paddingStart="20dp"
                app:tbgChildSpacingForLastRow="align"
                app:tbgChildSpacing="auto"
                app:tbgFlow="true"
                app:tbgRowSpacing="8dp"
                app:tbgCheckedButton="@drawable/round_rect_checked_bg"
                android:paddingTop="10dp"
                android:layout_centerInParent="true"
                android:id="@+id/nominal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="20dp"
                android:textColor="@color/selector_text"
                android:textSize="16sp" />

Thanks before!

i need different marker color and border color

i'm try this ,
toggle.setMarkerColor(Color.parseColor("#943D53")); this my marker color
unchecked toggle border also showing same color i need to set different border colour...

i hope for answer ...

center the buttons

I want to make this:
screenshot_2017-04-15-23-33-07

looks like this:
screenshot_2017-04-15-23-33-07xx

P.S.: I edited it with Paint, so it is not really fit to center.

I've tried to add android:gravity="center_horizontal" with app:tbgButtonSpacing="auto" inside the ToggleButtonGrop but it doesn't work.

I've tried to set app:tbgButtonSpacing="5dp" but it won't center the buttons, even I added the "android:gravity="center_horizontal"

Thanks before

Change toggle size

Is there any way to make the toggles a bit smaller? Thanks in advance, great library by the way!

Can not check a ToggleButton without triggering events

我使用ToggleButtonGroup时需要设置初始状态,不希望触发事件,调用

void check(int id)

结果还是触发了 ToggleButtonGroup.OnCheckedChangeListener 的事件。
查代码发现,check(int id)的确调了setCheckedId(id, false)(传了false不触发事件)
然而调的void setCheckedStateForView(int viewId, boolean checked) 转而调child的setChecked:

((Checkable) target).setChecked(checked)

在CompoundToggleButton的setChecked实现中,异步触发了OnCheckedChangeListener事件,这个OnCheckedChangeListener的实现就在ToggleButtonGroup及其子类中。在ToggleButtonGroup中则有:

@Override
protected <T extends View & Checkable> void onChildCheckedChange(T child, boolean isChecked) {
    if (isChecked) {
        if (mCheckedId != View.NO_ID && mCheckedId != child.getId()) {
            setCheckedStateForView(mCheckedId, false);
        }
        int id = child.getId();
        setCheckedId(id);
    }
}

上面的setCheckedId(id)触发了事件。

另外,SingleSelectToggleGroup如果在layout中设初始值也是触发事件的。这是否有必要?或者是否可以让用户选择?

layout_weight

I am trying to get the radio buttons to fill the width of the screen equally using layout_width="0dp" and layout_weight="1". Unfortunately, this is making the Radio buttons not show. Is there a different way to accomplish this in the library? This is the sample XML I am using.

`

<com.nex3z.togglebuttongroup.SingleSelectToggleGroup
    android:id="@+id/group_single_radiobutton"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    app:tbgFlow="true">

    <RadioButton
        android:layout_width="0dp"
        android:layout_height="40dp"
        android:layout_weight="1"
        android:background="@drawable/selector_bg_radio_button"
        android:button="@null"
        android:gravity="left"
        android:paddingBottom="8dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:paddingTop="8dp"
        android:text="First"
        android:textColor="@color/colorPrimary"
       />

    <RadioButton
        android:layout_width="0dp"
        android:layout_height="40dp"
        android:layout_weight="1"
        android:background="@drawable/selector_bg_radio_button"
        android:button="@null"
        android:gravity="center"
        android:paddingBottom="8dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:paddingTop="8dp"
        android:text="Second"
        android:textColor="@color/colorPrimary"
       />
</com.nex3z.togglebuttongroup.SingleSelectToggleGroup>

`

Set ToggleButton to Checked state by the string text?

Actually I am using your library to let the user select their "Interests", I am programmatically creating the interests and save the selected one on server as strings, then when a user logs in I get his interests as strings, I just want to know how can I set checked on those buttons which user has selected using the string values?
Thanks a lot for your help!

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.