From 9c034b7db18483d3b2bad24532aa1df04bc73af9 Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Wed, 6 Jun 2018 20:55:04 -0500 Subject: [PATCH] Fix crashes related to buggy ListView in Android --- .../view/fragment/SettingsFragment.java | 10 +++++++ .../view/overrides/SafeListView.java | 28 +++++++++++++++++++ app/src/main/res/layout/content_explorer.xml | 2 +- .../layout/preference_list_fragment_safe.xml | 14 ++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/wbrawner/simplemarkdown/view/overrides/SafeListView.java create mode 100644 app/src/main/res/layout/preference_list_fragment_safe.xml diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/SettingsFragment.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/SettingsFragment.java index 5688376..370b708 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/SettingsFragment.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/fragment/SettingsFragment.java @@ -9,6 +9,9 @@ import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; import com.wbrawner.simplemarkdown.R; import com.wbrawner.simplemarkdown.utility.Constants; @@ -42,6 +45,13 @@ public class SettingsFragment extends PreferenceFragment }); } + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { + + return inflater.inflate(R.layout.preference_list_fragment_safe, container, false); + } + @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Preference preference = findPreference(key); diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/overrides/SafeListView.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/overrides/SafeListView.java new file mode 100644 index 0000000..52ca59f --- /dev/null +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/overrides/SafeListView.java @@ -0,0 +1,28 @@ +package com.wbrawner.simplemarkdown.view.overrides; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.ListView; + +public class SafeListView extends ListView { + public SafeListView(Context context) { + super(context); + } + + public SafeListView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public SafeListView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + protected void onDetachedFromWindow() { + try { + super.onDetachedFromWindow(); + } catch (Exception ignored) { + // TODO: report this? + } + } +} diff --git a/app/src/main/res/layout/content_explorer.xml b/app/src/main/res/layout/content_explorer.xml index a33219d..178daf3 100644 --- a/app/src/main/res/layout/content_explorer.xml +++ b/app/src/main/res/layout/content_explorer.xml @@ -8,7 +8,7 @@ tools:context="com.wbrawner.simplemarkdown.view.activity.ExplorerActivity" tools:showIn="@layout/activity_explorer"> - + + + + + + \ No newline at end of file