Fix crashes related to buggy ListView in Android

This commit is contained in:
William Brawner 2018-06-06 20:55:04 -05:00 committed by William Brawner
parent e24e04734f
commit 9c034b7db1
4 changed files with 53 additions and 1 deletions

View file

@ -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);

View file

@ -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?
}
}
}

View file

@ -8,7 +8,7 @@
tools:context="com.wbrawner.simplemarkdown.view.activity.ExplorerActivity"
tools:showIn="@layout/activity_explorer">
<ListView
<com.wbrawner.simplemarkdown.view.overrides.SafeListView
android:id="@+id/file_list"
android:layout_width="0dp"
android:layout_height="0dp"

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:orientation="vertical">
<com.wbrawner.simplemarkdown.view.overrides.SafeListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>