我有 CheckBoxPreference,我想为其添加操作,请您在此实施中帮助我,
提前致谢,
这是我的xml代码:
<PreferenceCategory android:title="Test" >
<CheckBoxPreference
android:defaultValue="true"
android:key="test"
android:title="Tests" />
</PreferenceCategory>
执行
class TestActivity extends PreferenceActivity {
val checkboxPreference = true
val tests = getPreferenceManager.findPreference("test").asInstanceOf[CheckBoxPreference]
override def onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
addPreferencesFromResource(R.xml.preferences)
tests.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
def onPreferenceChange(preference: Preference, newValue: AnyRef): Boolean = {
if (newValue.toString == "true") {
Log.d("true")
} else {
Log.d("false")
}
true
}
})
}
}