make single-choice mode work in KeyChoiceAdapter

This commit is contained in:
Vincent Breitmoser
2018-06-30 12:31:57 +02:00
parent fdefd30a46
commit cdb95ee844
3 changed files with 3 additions and 2 deletions

View File

@@ -82,6 +82,8 @@ public class KeyChoiceAdapter extends FlexibleAdapter<KeyChoiceItem> {
throw new IllegalStateException("Cannot get active item in single select mode!"); throw new IllegalStateException("Cannot get active item in single select mode!");
} }
clearSelection();
Integer prevActiveItem = this.activeItem; Integer prevActiveItem = this.activeItem;
this.activeItem = newActiveItem; this.activeItem = newActiveItem;
@@ -89,6 +91,7 @@ public class KeyChoiceAdapter extends FlexibleAdapter<KeyChoiceItem> {
notifyItemChanged(prevActiveItem); notifyItemChanged(prevActiveItem);
} }
if (newActiveItem != null) { if (newActiveItem != null) {
toggleSelection(newActiveItem);
notifyItemChanged(newActiveItem); notifyItemChanged(newActiveItem);
} }
} }

View File

@@ -132,7 +132,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Select" android:text="Select"
android:id="@+id/button_select" android:id="@+id/button_select"
android:enabled="false"
style="?buttonBarButtonStyle" /> style="?buttonBarButtonStyle" />
</LinearLayout> </LinearLayout>

View File

@@ -116,7 +116,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Select" android:text="Select"
android:id="@+id/button_select" android:id="@+id/button_select"
android:enabled="false"
style="?buttonBarButtonStyle" /> style="?buttonBarButtonStyle" />
</LinearLayout> </LinearLayout>