Search code examples
androidandroid-preferencesandroid-holo-everywhere

how to findpreference() in holoeverywhere?


findpreference(R.id.myprefid) always returns null in my holoeverywhere preferenceActivity.I was unable to find an example for findpreference. Here is my preference xml:

<EditTextPreference
    holo:id="@+id/examiner_preference"
    android:inputType="textCapWords|textPersonName"
    holo:dialogTitle="@string/examiner_dialogTitle"
    holo:key="examiner_preference"
    holo:summary="@string/examiner_summary"
    holo:title="@string/examiner_name" />
<EditTextPreference
    holo:id="@+id/email"
    android:inputType="textEmailAddress"
    holo:dialogTitle="@string/prefs__title"
    holo:key="acra.user.email"
    holo:summary="@string/pref_a_summary"
    holo:title="@string/pref_aemail" />

I did everything suggested in this issue but still no success.

Please either suggest a solution or reference an example app which uses holoeverywhere's findpreference(). (I couldn't find one in demo app)


Solution

  • Update version 2:

    package ca.imaginauts.smartmed.fragments;
    
    import org.holoeverywhere.preference.EditTextPreference;
    import org.holoeverywhere.preference.PreferenceFragment;
    import android.os.Bundle;
    import ca.imaginauts.smartmed.R;
    
    public class SettingFragment extends PreferenceFragment
    {
        @Override
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
    
            // Load the preferences from an XML resource
            addPreferencesFromResource(R.xml.setting3);
    
            EditTextPreference email =  (EditTextPreference)findPreference("acra.user.email");
            email.setText("Hello World");
        }
    }
    

    inside setting3.xml

    <?xml version="1.0" encoding="utf-8"?>
    <PreferenceScreen xmlns:holo="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android" > 
    
    <EditTextPreference
        holo:id="@+id/examiner_preference"
        android:inputType="textCapWords|textPersonName"
        holo:dialogTitle="examiner_dialogTitle"
        holo:key="examiner_preference"
        holo:summary="examiner_summary"
        holo:title="examiner_name" />
    <EditTextPreference
        holo:id="@+id/email"
        android:inputType="textEmailAddress"
        holo:dialogTitle="prefs__title"
        holo:key="acra.user.email"
        holo:summary="pref_a_summary"
        holo:title="pref_aemail" />
    
    </PreferenceScreen>
    

    Screenshot of it working

    Original version

    I honestly have never been able to get the Id's in HoloEverywhere.findPreference(R.id.examiner_preference) to work. I always forced to use the keys.

    (Keys as in holo:key value)

    So try this

       EditTextPreference emailPrefs = (EditTextPreference)findPreference("acra.user.email");
    

    I haven't found specific reason, but I haven't had an issue using the holo:keys in terms of performance or bugs. Might be a compromise for you.