我真的需要一些帮助! Logcat不会发出任何错误,也不会发出代码错误,并且仍然没有任何反应。我有2个正常的“偏好设置”“ ueber”,只要单击它就可以使用,而“ update”则永不调用。我知道,因为我将“ ueber”的确切代码复制到了“ update”,但仍然没有发生任何事情……我已经在此方面坐了2个弱点,而你们是我的最后希望!

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")@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferencesettings2);@Overridepublic 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;}

最佳答案

尝试使用findPreference找到首选项并调用setOnPreferenceClickListener

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferencesettings2);
    findPreference("about").setOnPreferenceClickListener(this);
    findPreference("update").setOnPreferenceClickListener(this);
}

10-07 18:48