Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should be able to remove:</p> <pre><code>&lt;EditTextPreference android:key="preference_character_blacklist" android:title="Character blacklist" android:visibility="gone"/&gt; </code></pre> <p>from your preferences.xml. This will stop it from appearing in the Settings menu.</p> <p>For the setting to work internally I would suggest reading into <a href="http://developer.android.com/reference/android/content/SharedPreferences.html" rel="nofollow">SharedPreferences</a>. The <a href="http://developer.android.com/guide/topics/data/data-storage.html#pref" rel="nofollow">Android Storage Options Guide</a> will explain how you can store and retrieve setting values using <code>SharedPreferences</code>.</p> <p>I've modified the following example to store a string from the guide linked above:</p> <pre><code>public class Calc extends Activity { public static final String PREFS_NAME = "MyPrefsFile"; @Override protected void onCreate(Bundle state){ super.onCreate(state); . . . // Restore preferences SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); String silent = settings.getString("character_blacklist", ""); } @Override protected void onStop(){ super.onStop(); // We need an Editor object to make preference changes. // All objects are from android.context.Context SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); //Some test characters for the blacklist mBlackListChars = "a,g,t,h,f"; editor.putString("character_blacklist", mBlackListChars); // Commit the edits editor.commit(); } } </code></pre> <p>Please note you will probably want to call these methods outside of <code>onCreate()</code> and <code>onStop()</code>, this is purely for illustration. In addition I'll draw your attention to the fact <code>SharedPreferences</code> can handle a <code>StringSet</code> which may be useful to you in storing multiple characters. See the <code>getStringSet()</code> method in <code>SharedPreferences</code>.</p> <p><strong>UPDATE</strong></p> <p>In order to keep the preference but just hide it from the user you could remove it programatically. Seems like a bit of a hack but consider adding this to your 'OnCreate()' in your 'PreferenceActivity'</p> <pre><code>getPreferenceScreen().removePreference(editTextPreferenceCharacterBlacklist); </code></pre> <p><strong>UPDATE</strong></p> <p>Looks like your problem is caused by editTextPreferenceCharacterBlacklist being null. Problem because it's not been set to your instance variable at the point you are running the line I specified. You could try finding it as follows:</p> <p><code>getPreferenceScreen().removePreference(getPreferenceScreen().findPreference(KEY_CHARACTER_BLACKLIST));</code></p>
    singulars
    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.
    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