Example usage for android.preference PreferenceScreen onItemClick

List of usage examples for android.preference PreferenceScreen onItemClick

Introduction

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

Prototype

public void onItemClick(AdapterView parent, View view, int position, long id) 

Source Link

Usage

From source file:at.jclehner.rxdroid.DrugEditFragment.java

private void performPreferenceClick(String key) {
    final PreferenceScreen ps = getPreferenceScreen();
    for (int i = 0; i != ps.getPreferenceCount(); ++i) {
        if (key.equals(ps.getPreference(i).getKey())) {
            ps.onItemClick(getListView(), null, i, 0);
            break;
        }/*from  w  ww .  j ava2s  . c o m*/
    }
}

From source file:de.tum.in.tumcampus.fragments.SettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);

    mContext = getActivity();/*from  www .  j  a  v  a  2 s. com*/

    // Disables silence service if the app is used without TUMOnline access
    CheckBoxPreference silent = (CheckBoxPreference) findPreference("silent_mode");
    if (!new AccessTokenManager(mContext).hasValidAccessToken()) {
        silent.setEnabled(false);
    }

    // Click listener for preference list entries. Used to simulate a button
    // (since it is not possible to add a button to the preferences screen)
    findPreference("button_wizard").setOnPreferenceClickListener(this);
    findPreference("button_clear_cache").setOnPreferenceClickListener(this);
    findPreference("facebook").setOnPreferenceClickListener(this);
    findPreference("github").setOnPreferenceClickListener(this);
    findPreference("first_run").setOnPreferenceClickListener(this);
    findPreference("licenses").setOnPreferenceClickListener(this);
    findPreference("feedback").setOnPreferenceClickListener(this);
    findPreference("privacy").setOnPreferenceClickListener(this);

    // Set summary for these preferences
    setSummary("card_cafeteria_default_G");
    setSummary("card_cafeteria_default_K");
    setSummary("card_cafeteria_default_W");
    setSummary("card_role");
    setSummary("card_stations_default_G");
    setSummary("card_stations_default_C");
    setSummary("card_stations_default_K");
    setSummary("card_default_campus");
    setSummary("silent_mode_set_to");
    setSummary("background_mode_set_to");

    // Register the change listener to react immediately on changes
    PreferenceManager.getDefaultSharedPreferences(mContext).registerOnSharedPreferenceChangeListener(this);

    // Populate news sources
    populateNewsSources();

    // Open a card's preference screen if selected from it's context menu
    Bundle bundle = getArguments();
    if (bundle != null && bundle.containsKey(Const.PREFERENCE_SCREEN)) {
        final String key = bundle.getString(Const.PREFERENCE_SCREEN);

        PreferenceScreen screen = (PreferenceScreen) findPreference("cards_pref_container");
        final PreferenceScreen cardPreferenceScreen = (PreferenceScreen) findPreference(key);
        cardPreferenceScreen.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                initializeActionBar(cardPreferenceScreen);
                return true;
            }
        });

        final ListAdapter listAdapter = screen.getRootAdapter();
        final int itemsCount = listAdapter.getCount();
        for (int i = 0; i < itemsCount; ++i) {
            if (listAdapter.getItem(i).equals(cardPreferenceScreen)) {
                screen.onItemClick(null, null, i, 0);
                break;
            }
        }
    }
}

From source file:com.ubuntuone.android.files.activity.PreferencesActivity.java

private void openPreference(String key) {
    PreferenceScreen screen = getPreferenceScreen();
    Log.d(TAG, "screen not null");
    if (screen != null) {
        ListAdapter adapter = getPreferenceScreen().getRootAdapter();
        for (int i = 0; i < adapter.getCount(); i++) {
            Preference p = (Preference) adapter.getItem(i);
            Log.d(TAG, "key is: " + p.getKey());
            if (p.getKey().equals(key)) {
                screen.onItemClick(null, null, i, 0);
                break;
            }/*from w  w w .j a v a 2  s.  c om*/
        }
    }
}