Code example for PreferenceCategory

Methods: findPreference

0
 
    public void onCreate() { 
 
        mParent = mFragment.getPreferenceScreen();
        mVoiceCategory = (PreferenceCategory) mParent.findPreference(KEY_VOICE_CATEGORY);
        mRecognizerPref = (ListPreference) mVoiceCategory.findPreference(KEY_RECOGNIZER);
        mRecognizerSettingsPref = mVoiceCategory.findPreference(KEY_RECOGNIZER_SETTINGS);
        mTtsSettingsPref = mVoiceCategory.findPreference(KEY_TTS_SETTINGS);
        mRecognizerPref.setOnPreferenceChangeListener(this);
        mSettingsPref = (PreferenceScreen)
                mVoiceCategory.findPreference(KEY_RECOGNIZER_SETTINGS);
 
        mAvailableRecognizersMap = new HashMap<String, ResolveInfo>();
 
        populateOrRemovePreferences(); 
    } 
 
    private void populateOrRemovePreferences() { 
        boolean hasRecognizerPrefs = populateOrRemoveRecognizerPrefs();
        boolean hasTtsPrefs = populateOrRemoveTtsPrefs();
        if (!hasRecognizerPrefs && !hasTtsPrefs) {
            // There were no TTS settings and no recognizer settings, 
            // so it should be safe to hide the preference category 
            // entirely. 
            mFragment.getPreferenceScreen().removePreference(mVoiceCategory);
        } 
    } 
 
    private boolean populateOrRemoveRecognizerPrefs() { 
        List<ResolveInfo> availableRecognitionServices =