1

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)

Mehdi Fanai
  • 4,021
  • 13
  • 50
  • 75

1 Answers1

0

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.

Jerad
  • 709
  • 5
  • 11
  • It still returns null as i stated above. I use findPreference() in onCreate(). is this right? Can you post your preferenceActivity code please? – Mehdi Fanai Jul 01 '13 at 18:40
  • You mention you use findpreference(R.id.myprefid), I am saying using findpreference("holo key string"). I'll will update my question with some sample code – Jerad Jul 01 '13 at 18:42
  • I update my answer with sample code, are you still running into issue? If so what device are using and version of Android? – Jerad Jul 01 '13 at 19:13
  • Im using prefenceActivity and not the PreferenceFragment.Im using headers to build prefs.that might be the issue.im running on android 4.2.1 in emulator and 4.1 on my galaxy s2.Thanks for taking time:-) – Mehdi Fanai Jul 01 '13 at 19:30
  • Can you post your PreferenceActivity code and your headers.xml if it not already posted. – Jerad Jul 01 '13 at 19:37