Android的我如何在preferenceScreen长时间操作过程中禁用复选框 [英] Android how do i disable checkbox during a long operation in PreferenceScreen
问题描述
我从XML加载此preferenceScreen。
问题是,当我切换复选框即时通讯开始服务withs
需要像5-10秒来连接到服务器。
我怎样才能在此期间禁用的复选框。
由于布局充气我看不到如何让checkbox.setEnable =假的?
I have this PreferenceScreen loaded from 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);
}
}
推荐答案
有你的 preferenceActivity
实施在preferenceChangeListener
,然后用它注册您的复选框。当你发现它已被pressed禁用preference
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);
这篇关于Android的我如何在preferenceScreen长时间操作过程中禁用复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!