Bearded-Hen / Android-Bootstrap

Bootstrap style widgets for Android, with Glyph Icons
MIT License
7.28k stars 1.43k forks source link

BootstrapGroupButton BootstrapButton type radio act as Toggle button ? #175

Closed khalid-mahmood closed 7 years ago

khalid-mahmood commented 8 years ago

BoostrapGroupButton BootstrapButton type "radio" acting as toggle button. Radio button behaviour one should always checked !! how it is possible ? Thanks

khalid-mahmood commented 8 years ago

I have Create BoostrapGroupButton and set type to "radio" when i click to any button its checked but when i click same button again its unchecked while radio button behavior is once checked it can't unchecked. one would be always selected from group... i have already checked first button.

khalid-mahmood commented 8 years ago

@jamie-beardedhen any help ?

jamie-beardedhen commented 8 years ago

@khalid-mahmood please include a minimal code example so that someone can verify this

khalid-mahmood commented 8 years ago

<LinearLayout android:id="@+id/tabs_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal">

    <com.beardedhen.androidbootstrap.BootstrapButtonGroup
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:orientation="horizontal"
        app:bootstrapBrand="custom"
        app:bootstrapSize="xs"
        app:buttonMode="radio"
        app:roundedCorners="true"
        app:showOutline="true">

        <com.beardedhen.androidbootstrap.BootstrapButton
            android:id="@+id/about_button"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="About School"
            app:checked="true" />

        <com.beardedhen.androidbootstrap.BootstrapButton
            android:id="@+id/chairperson_button"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Chairperson Message" />

        <com.beardedhen.androidbootstrap.BootstrapButton
            android:id="@+id/gallery_button"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Gallery" />
    </com.beardedhen.androidbootstrap.BootstrapButtonGroup>
</LinearLayout>

this is xml

btton.setOnCheckedChangedListener(new BootstrapButton.OnCheckedChangedListener() { @Override public void OnCheckedChanged(BootstrapButton bootstrapButton, boolean isChecked) { if (isChecked) { ..... } } });

screenshot_2016-10-18-13-15-03 initial then after click again on "about school" button screenshot_2016-10-18-13-15-11

while it should be selected beacuse its a radio not toggle

Hope so you better understand now. @jamie-beardedhen

khalid-mahmood commented 8 years ago

@jamie-beardedhen Waiting for answer. help please

jamie-beardedhen commented 7 years ago

Fixed in 2.3.1

khalid-mahmood commented 7 years ago

@jamie-beardedhen
if button is previously checked and click again its return true again although it should return true only first if not checked. i don't want to trigger action again on same button if its is already checked. any sugguestion ?

khalid-mahmood commented 7 years ago

Change BootstrapButton Class

@Override
public void setSelected(boolean selected) {
    if (onCheckedChangedListener != null) {
        onCheckedChangedListener.OnCheckedChanged(this, selected);
    }
    super.setSelected(selected);

}

and use if (!bootstrapButton.isSelected() && isChecked) { .... } did the trick for me.