From c7462a117398c9502856c0da247d5921fb74f412 Mon Sep 17 00:00:00 2001 From: Maxr1998 Date: Wed, 28 Oct 2020 16:48:21 +0100 Subject: [PATCH] Fix crash due to StateListAnimator.clone missing on some devices --- .../de/Maxr1998/modernpreferences/PreferencesAdapter.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/de/Maxr1998/modernpreferences/PreferencesAdapter.kt b/library/src/main/java/de/Maxr1998/modernpreferences/PreferencesAdapter.kt index 9a6f9251..ca12e0a4 100644 --- a/library/src/main/java/de/Maxr1998/modernpreferences/PreferencesAdapter.kt +++ b/library/src/main/java/de/Maxr1998/modernpreferences/PreferencesAdapter.kt @@ -151,7 +151,13 @@ class PreferencesAdapter @VisibleForTesting constructor( else -> R.layout.map_preference } val view = layoutInflater.inflate(layout, parent, false) - view.stateListAnimator = stateListAnimator?.clone() + view.stateListAnimator = try { + stateListAnimator?.clone() + } catch (e: NoSuchMethodError) { + // Some awful Android 5 devices apparently don't implement the clone method, + // although it's part of the Android SDK since API 21. Thus, we catch it and return null instead. + null + } if (viewType > 0) layoutInflater.inflate(viewType, view.findViewById(R.id.map_widget_frame), true) return ViewHolder(view)