问题描述
我要在preferncescreen许多复选框preference,并有注册改变每个复选框的价值和怎么做,如果基于某些任务,其打开或off.How办这复选框preference?
我知道跟下面的code为此在复选框:
I have to have many checkboxpreference in preferncescreen and have to register each checkbox value changed and do some task based on if its on or off.How do I do this in checkboxpreference?I know to do this in checkbox with the below code:
public void onCheckboxClicked(View view) {
// Is the view now checked?
boolean checked = ((CheckBox) view).isChecked();
// Check which checkbox was clicked
switch(view.getId()) {
case R.id.Activate:
if (checked){
// Put some meat on the sandwich
Toast.makeText(Daydream.this, "checked!", Toast.LENGTH_LONG).show();
}else
// Remove the meat
Toast.makeText(Daydream.this, "UNchecked!", Toast.LENGTH_LONG).show();
break;
case R.id.sencond_id:
if (checked){
// Cheese me
}else
// I'm lactose intolerant
break;
// TODO: Veggie sandwich
}
}
但我不知道没有办法做到像上面这样做与复选框preference.Is呢?我知道,preferencescreen是pcated德$ P $但我不得不使用它,因为简单的来使listview.I的两行希望我得到的答复soon.Thanks
But I dont know to do this with checkboxpreference.Is there any way to do like above?I know that the preferencescreen is deprecated but I have to use it because of simplicity to make two lines of listview.I hope I get a reply soon.Thanks
推荐答案
使用它像这样
final Preference otherpref = (Preference) findPreference("otherpref");
final Preference pref = (Preference) findPreference("checkbox");
pPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Toast.makeText(getBaseContext(), "Some text", Toast.LENGTH_SHORT).show();
return true;
}
});
otherpref .setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Toast.makeText(getBaseContext(), "Other text", Toast.LENGTH_SHORT).show();
return true;
}
});
这篇关于复选框preference监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!