findpreference(R.id.myprefid)总是在我的holoeverywhereA活动中返回null。我无法找到findpreference的示例。这是我的偏好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" />
我在this issue做了所有建议,但仍然没有成功。
请建议一个解决方案或引用一个使用holoeverywhere的findpreference()的示例应用程序。 (我在演示应用程序中找不到一个)
答案 0 :(得分:0)
更新版本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");
}
}
在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>
老实说,我从来没有能够在HoloEverywhere.findPreference(R.id.examiner_preference)中获得Id。我总是被迫使用键。
(全息中的键:键值)
所以试试这个
EditTextPreference emailPrefs = (EditTextPreference)findPreference("acra.user.email");
我没有找到具体原因,但我在使用holo:key时没有出现性能或错误问题。可能是你的妥协。