相关疑难解决方法(0)

ChipGroup单选

我怎样才能强迫一个ChipGroup人像RadioGroup至少一个选定的项目一样?设置setSingleSelection(true)还增加了在a上单击两次时没有选择任何内容的可能性Chip.

android android-chips material-components material-components-android

14
推荐指数
5
解决办法
3650
查看次数

从 ChipGroup 中获取选定的 Chips

我是在 Android 中使用 Chips 的新手。我想在单击按钮时从 ChipGroup 中获取选定的筹码。Made 以某种方式检查每个 Chip 并将其添加到 Set 中,但希望使其更有效率。不知何故,我自己没有找到我的问题的答案。

当我检查 2 Chips 并取消选中我检查的第一个 Chips 时,也会出现错误。

这是我的代码:

<com.google.android.material.chip.ChipGroup
                android:id="@+id/chipGroup"
                android:layout_width="300dp"
                android:layout_height="wrap_content"

                >

                <com.google.android.material.chip.Chip
                    android:id="@+id/chip1"
                    style="@style/Widget.MaterialComponents.Chip.Filter"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="1"
                    android:backgroundTint="#99FFFFFF"
                    />

                <com.google.android.material.chip.Chip
                    android:id="@+id/chip2"
                    style="@style/Widget.MaterialComponents.Chip.Filter"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2"
                    android:backgroundTint="#99FFFFFF"/>


                <com.google.android.material.chip.Chip
                    android:id="@+id/chip3"
                    style="@style/Widget.MaterialComponents.Chip.Filter"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="3"
                    android:backgroundTint="#99FFFFFF"/>

                <com.google.android.material.chip.Chip
                    android:id="@+id/chip4"
                    style="@style/Widget.MaterialComponents.Chip.Filter"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="4"
                    android:backgroundTint="#99FFFFFF"/>

                <com.google.android.material.chip.Chip
                    android:id="@+id/chip5"
                    style="@style/Widget.MaterialComponents.Chip.Filter"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="5"
                    android:backgroundTint="#99FFFFFF"/>

            </com.google.android.material.chip.ChipGroup>
Run Code Online (Sandbox Code Playgroud)
Set<Integer> chipIds = new HashSet<>();

int chip1Id= 1;
int chip2Id= 2;
int chip3Id= 3;
int chip4Id= 4;
int chip5Id= …
Run Code Online (Sandbox Code Playgroud)

android android-chips

4
推荐指数
2
解决办法
6959
查看次数