customPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Toast.makeText(getBaseContext(),
"The custom preference has been clicked",
Toast.LENGTH_LONG).show();
SharedPreferences customSharedPreference =
getSharedPreferences(
"myCustomSharedPrefs", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor =
customSharedPreference
.edit();
editor.putString("myCustomPref",
"The preference has been clicked");
editor.commit();
return true;
}
});
上面的代碼工作正常如何瀏覽從一個活動到另一個活動onPreferenceClick
但是當我嘗試使用下面
customPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Intent int1 = new Intent(getBaseContext(),
termandcondition.class);
getBaseContext().startActivity(int1);
return true;
}
});
它給人錯誤,請告訴我如何implment它
登錄
12-10 15:34:20.405: E/AndroidRuntime(377): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.adodis.taxmann/com.adodis.taxmann.termandcondition}: java.lang.NullPointerException Error is coming
可能重複[如何去針對Android偏好屏幕的另一項活動(http://stackoverflow.com/questions/13833951/how-to-go-another在Android中的活動從首選屏幕) – Damon