我有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
}
})
}
}