How to Multichoice Options That Appears When Clicking Single Chocie in Android

366 Views Asked by At

I want something like this. There could be passive multichoice buttons below all of the single choices. It doesn't matter. Is that possible?

Single and Multiple Choice Dialog

1

There are 1 best solutions below

2
Łukasz Kobyliński On BEST ANSWER

You can control visibility of every view with view.setVisibility(View.Visible or View.Gone). Set click listener on single choice button and use that method to show container layout with radio buttons.

chkIos.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View view) {        
    if (v.isChecked()) {
        multiChoiceView.setVisibility(View.VISIBLE);
    } else {
        multiChoiceView.setVisibility(View.GONE);
    }

});

To build a layout like on your picture you can combine RadioGroup with LinearLayout under each RadioButton, in this way:

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:orientation="vertical">

        <CheckBox
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <CheckBox
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <CheckBox
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RadioGroup>