private void BindPreferences() { PreferenceScreen preferenceScreen = PreferenceScreen; if (preferenceScreen != null) { preferenceScreen.Bind(GetListView()); } if (Build.VERSION.SdkInt <= BuildVersionCodes.GingerbreadMr1) { // Workaround android bug for SDK 10 and below - see // https://github.com/android/platform_frameworks_base/commit/2d43d283fc0f22b08f43c6db4da71031168e7f59 GetListView().ItemClick += (sender, e) => { int position = e.Position; // If the list has headers, subtract them from the index. if (e.Parent is ListView) { position -= ((ListView)e.Parent).HeaderViewsCount; } Java.Lang.Object item = preferenceScreen.RootAdapter.GetItem(position); if (!(item is Preference)) { return; } Preference preference = (Preference)item; try { Method performClick = Java.Lang.Class.FromType(typeof(Preference)).GetDeclaredMethod("performClick", Java.Lang.Class.FromType(typeof(PreferenceScreen))); performClick.Accessible = true; performClick.Invoke(preference, preferenceScreen); } catch (InvocationTargetException ex) { } catch (IllegalAccessException ex) { } catch (NoSuchMethodException ex) { } }; } }
public void BindPreferences() { PreferenceScreen preferenceScreen = PreferenceScreen; if (preferenceScreen != null) { preferenceScreen.Bind(GetListView()); } if (Build.VERSION.SdkInt <= BuildVersionCodes.GingerbreadMr1) { // Workaround android bug for SDK 10 and below - see // https://github.com/android/platform_frameworks_base/commit/2d43d283fc0f22b08f43c6db4da71031168e7f59 GetListView().ItemClick += (object sender, Android.Widget.AdapterView.ItemClickEventArgs e) => { // If the list has headers, subtract them from the index. int pos = e.Position; if (sender is ListView) { pos -= ((ListView)sender).HeaderViewsCount; } Java.Lang.Object item = PreferenceScreen.RootAdapter.GetItem(pos); if (!(item is Preference)) { return; } Preference preference = (Preference)item; try { Method performClick = Class.FromType(typeof(Preference)).Class.GetDeclaredMethod("performClick", Class.FromType(typeof(PreferenceScreen))); performClick.Accessible = true; performClick.Invoke(preference, preferenceScreen); } catch (InvocationTargetException e1) { Console.WriteLine(Tag + " " + e1.Message); } catch (IllegalAccessException e2) { Console.WriteLine(Tag + " " + e2.Message); } catch (NoSuchMethodException e3) { Console.WriteLine(Tag + " " + e3.Message); } }; } }