I have this PreferenceScreen loaded from 开发者_StackOverflow社区xml. The thing is when i toggle the checkbox im starting a service withs need like 5-10 sec to connect to a server. How can i disable the checkbox during this time. Since the layout is inflated i cant see how to get checkbox.setEnable = false?
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="checkBoxenableincomingcall"
android:title="Enable incoming call"
android:defaultValue="true"
android:summary="hasse running as background service" />
<CheckBoxPreference
android:key="checkBoxmakephoneringonincoming"
android:title="Dont ring on message"
android:defaultValue="true"
android:summary="dont disturb me" />
<EditTextPreference
android:key="edittexvalue"
android:title="EditText"
android:summary="EditTextPreference" />
public class EditPreferences extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
have your PreferenceActivity
implement OnPreferenceChangeListener
and then register your checkbox with it. When you detect that it has been pressed disable the preference
//in onCreate
findPreference("checkboxpreferencekey").setOnPreferenceChangeListener(this);
public boolean onPreferenceChange(Preference preference, Object newValue){
if(preference.getKey().equals("checkboxpreferencekey")){
preference.setEnabled(false);
return true;
}
else return true;
}
That is how you can disable it, you will still need some sort of callback or broadcast from your service to know when to enable it again. But when its time you do it the same way.
findPreference("checkboxpreferencekey").setEnabled(true);
精彩评论