[Chip] Update chipgroup demo to include switch to toggle the requiredSelection attr.

PiperOrigin-RevId: 324015228
This commit is contained in:
connieshi 2020-07-30 12:13:03 -04:00 committed by Daniel Nizri
parent 84fd465cea
commit 4b01ac4b22
3 changed files with 22 additions and 1 deletions

View File

@ -34,6 +34,7 @@ import io.material.catalog.feature.DemoFragment;
public class ChipGroupDemoFragment extends DemoFragment {
private SwitchMaterial singleSelectionSwitch;
private SwitchMaterial selectionRequiredSwitch;
@Nullable
@Override
@ -42,6 +43,8 @@ public class ChipGroupDemoFragment extends DemoFragment {
View view = layoutInflater.inflate(getChipGroupContent(), viewGroup, false /* attachToRoot */);
singleSelectionSwitch = view.findViewById(R.id.single_selection);
selectionRequiredSwitch = view.findViewById(R.id.selection_required);
ChipGroup reflowGroup = view.findViewById(R.id.reflow_group);
ChipGroup scrollGroup = view.findViewById(R.id.scroll_group);
@ -53,6 +56,16 @@ public class ChipGroupDemoFragment extends DemoFragment {
initChipGroup(reflowGroup);
initChipGroup(scrollGroup);
});
selectionRequiredSwitch.setOnCheckedChangeListener(
(buttonView, isChecked) -> {
reflowGroup.setSelectionRequired(isChecked);
scrollGroup.setSelectionRequired(isChecked);
initChipGroup(reflowGroup);
initChipGroup(scrollGroup);
});
initChipGroup(reflowGroup);
initChipGroup(scrollGroup);

View File

@ -29,7 +29,13 @@
android:layout_height="wrap_content"
android:text="@string/cat_chip_group_single_selection_text"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/selection_required"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cat_chip_group_selection_required_text"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/cat_chip_group_refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -31,6 +31,8 @@
<string name="cat_chip_group_demo_title">Chip Group Demo</string>
<string name="cat_chip_group_single_selection_text">Single selection</string>
<string name="cat_chip_group_selection_required_text">Selection required</string>
<string name="cat_chip_reflow_group">Reflowing chip group</string>
<string name="cat_chip_scroll_group">Scrolling chip group</string>