Note that there are some explanatory texts on larger screens.

plurals
  1. POshow and hide preferences in android
    primarykey
    data
    text
    <p>I have a preference.xml file, and I want to show or hide some of the entry of this file. But the problem is that the preferences aren't hidden. My code is the following:</p> <pre><code> @Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); Preference customPref = (Preference) findPreference(getText(R.string.about)); customPref.setOnPreferenceClickListener(this); Preference termAndConditions = (Preference) findPreference(getText(R.string.term_and_conditions)); termAndConditions.setOnPreferenceClickListener(this); Preference privacyStatement = (Preference) findPreference(getText(R.string.privacy_statement)); privacyStatement.setOnPreferenceClickListener(this); Preference login_with_facebook = (Preference) findPreference(getText(R.string.login_with_facebook)); login_with_facebook.setOnPreferenceClickListener(this); Preference register_new_account = (Preference) findPreference(getText(R.string.register_new_account)); register_new_account.setOnPreferenceClickListener(this); Preference login = (Preference) findPreference(getText(R.string.login)); login.setOnPreferenceClickListener(this); Preference my = (Preference) findPreference(getText(R.string.my)); my.setOnPreferenceClickListener(this); Preference miles_and_more = (Preference) findPreference(getText(R.string.miles_and_more)); miles_and_more.setOnPreferenceClickListener(this); Preference voucher_booking = (Preference) findPreference(getText(R.string.voucher_booking)); voucher_booking.setOnPreferenceClickListener(this); Preference invite_friends = (Preference) findPreference(getText(R.string.invite_friends)); invite_friends.setOnPreferenceClickListener(this); } onResume{ buildLogin() } private void buildLogin() { PreferenceScreen preferenceScreen = getPreferenceScreen(); hidePreferences(preferenceScreen, R.string.my); hidePreferences(preferenceScreen, R.string.miles_and_more); hidePreferences(preferenceScreen, R.string.voucher_booking); hidePreferences(preferenceScreen, R.string.invite_friends); } private void hidePreferences(PreferenceScreen preferenceScreen, int preferenceKey) { Preference customPref = (Preference) findPreference(getText(preferenceKey)); preferenceScreen.removePreference(customPref); } </code></pre> <p>the idea is to hide some of the preferences on onResume(). This class is extending from PreferenceFragment. Can some one please point what am I doing wrong. None of the preferences are hidden.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload