当我的偏好之一被点击时,我试图打开一个网站(而不是当偏好实际改变时,因为没有一个)。
问题是onPreferenceClick()
从未调用过。
这是我的PreferenceActivity
:
public class About extends PreferenceActivity implements
OnPreferenceClickListener {
TextView tv_developer;
TextView tv_version;
String versionName;
int counter = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.about);
Preference p_developer = (Preference) findPreference("p_developer");
p_developer.setOnPreferenceClickListener(this);
Preference p_licences = (Preference) findPreference("p_licences");
p_licences.setOnPreferenceClickListener(this);
}
@Override
public boolean onPreferenceClick(Preference pref) {
// TODO Auto-generated method stub
Log.i("Anything pressed", "YES");
if (pref.getKey().equals("p_developer")) {
Log.i("p_developer", "YES");
} else {
Log.i("p_developer", "NO");
}
return true;
}
}
这是xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="about"
android:title="About" >
<Preference
style="?android:preferenceInformationStyle"
android:key="p_licences"
android:title="p_licences" />
<PreferenceCategory android:title="Category" >
<Preference
style="?android:preferenceInformationStyle"
android:key="p_developer"
android:title="p_developer" />
</PreferenceCategory>
</PreferenceScreen>
我还发现这也无济于事:
<Preference android:title="@string/prefs_web_page" >
<intent android:action="android.intent.action.VIEW"
android:data="http://www.example.com" />
</Preference>