我真的需要一些帮助! Logcat没有发出任何错误,代码中没有错误,仍然没有发生任何事情。我有两个正常的偏好" ueber",它可以在我点击它的任何时候工作,并且#34;更新",它从未被调用过。我知道,因为我复制了" ueber"的确切代码。到"更新"而且仍然没有发生任何事情......我已经坐在那两个弱点上了,你们是我最后的希望!
preferencesettings2.xml
<PreferenceScreen>
<PreferenceCategory android:title="Info">
<Preference
android:key="update"
android:title="Update"
android:summary="Check for updates"/>
<Preference
android:key="about"
android:title="About"
android:summary="Shows information"/>
</PreferenceCategory>
</PreferenceScreen>
Preferencesettings2.java
public class Preferencesettings2 extends PreferenceActivity implements OnPreferenceClickListener {
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferencesettings2);
@Override
public boolean onPreferenceClick(Preference preference) {
if(preference.getKey().equals("update")){
download();
}else if(preference.getKey().equals("about")){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Preferencesettings2.this);
alertDialogBuilder.setTitle("about");
alertDialogBuilder.setMessage("About");
alertDialogBuilder.setCancelable(true);
alertDialogBuilder.setNeutralButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
dialog.cancel();
}
});
alertDialogBuilder.show();
}
return true;
}
答案 0 :(得分:2)
尝试使用findPreference
找到偏好并调用setOnPreferenceClickListener
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferencesettings2);
findPreference("about").setOnPreferenceClickListener(this);
findPreference("update").setOnPreferenceClickListener(this);
}