Example usage for android.preference PreferenceScreen bind

List of usage examples for android.preference PreferenceScreen bind

Introduction

In this page you can find the example usage for android.preference PreferenceScreen bind.

Prototype

public void bind(ListView listView) 

Source Link

Document

Binds a ListView to the preferences contained in this PreferenceScreen via #getRootAdapter() .

Usage

From source file:com.achep.base.ui.fragments.PreferenceFragmentBase.java

private void bindPreferences() {
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    if (preferenceScreen != null) {
        preferenceScreen.bind(getListView());
    }//from www . j  a v  a 2  s .co  m
    onBindPreferences();
}

From source file:com.zoromatic.flashlight.PreferenceFragment.java

private void bindPreferences() {
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    if (preferenceScreen != null) {
        preferenceScreen.bind(getListView());

        ListView list = getListView();

        if (list != null && list.getCount() > 0) {
            for (int i = 0; i < list.getCount(); i++) {
                View view = getViewByPosition(i, list);

                if (view != null) {
                    setListViewItem(view);
                }/*w w  w. j ava2  s. co m*/
            }
        }
    }

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
        // Workaround android bug for SDK 10 and below - see
        // https://github.com/android/platform_frameworks_base/commit/2d43d283fc0f22b08f43c6db4da71031168e7f59
        getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // If the list has headers, subtract them from the index.
                if (parent instanceof ListView) {
                    position -= ((ListView) parent).getHeaderViewsCount();
                }

                Object item = preferenceScreen.getRootAdapter().getItem(position);
                if (!(item instanceof Preference))
                    return;

                final Preference preference = (Preference) item;
                try {
                    Method performClick = Preference.class.getDeclaredMethod("performClick",
                            PreferenceScreen.class);
                    performClick.setAccessible(true);
                    performClick.invoke(preference, preferenceScreen);
                } catch (InvocationTargetException e) {
                } catch (IllegalAccessException e) {
                } catch (NoSuchMethodException e) {
                }
            }
        });
    }
}