因此,基本上,我有一个PreferenceActivity,用于通过扩展AsyncTask的私有类调用Web。每当偏好发生变化时,我就会有一个“大”的“开关情况”,确定哪种偏好已经更改,然后相应地进行调用。
现在我有两个问题:
,
相关代码片段:
public void onSharedPreferenceChanged(SharedPreferences arg0, String key)
{
if(isFirstRun)
return;
// Call Forward Preferences
if(key.contentEquals("call_forward_always"))
{
cfInfo[0] = "1";
cfInfo[1] = arg0.getString(key, "ERROR");
new PushCallForwardInfoTask().execute(cfInfo);
ep1.setSummary("Viderestiller til " + cfInfo[1]);
}
else if(key.contentEquals("call_forward_busy"))
{
cfInfo[2] = "1";
cfInfo[3] = arg0.getString(key, "ERROR");
new PushCallForwardInfoTask().execute(cfInfo);
ep2.setSummary("Viderestiller til " + cfInfo[3]);
}
else if(key.contentEquals("call_forward_noresponse"))
{
cfInfo[4] = "1";
cfInfo[5] = arg0.getString(key, "ERROR");
new PushCallForwardInfoTask().execute(cfInfo);
ep3.setSummary("Viderestiller til " + cfInfo[5]);
}
else if(key.contentEquals("call_forward_timeout"))
{
cfInfo[6] = arg0.getString(key, "ERROR");
new PushCallForwardInfoTask().execute(cfInfo);
ep4.setSummary("Viderestiller efter " + cfInfo[6] + " sekunder");
}
// Show Number Preferences
else if(key.contentEquals("shownumber_list"))
{
String[] newnumber = {""};
newnumber[0] = arg0.getString(key, "ERROR");
new PushNumberTask().execute(newnumber);
lp.setSummary(arg0.getString(key, "ERROR"));
}
// Voicemail Preferences
else if(key.contentEquals("voicemail_checkbox"))
{
final Boolean[] vmStatus = { Boolean.FALSE };
vmStatus[0] = cp.isChecked();
new PushVoicemailStatus().execute(vmStatus);
}
}发布于 2012-03-15 12:41:09
要回答你的第一个问题,如果你不想使用一个大开关/大小写语句,你最好的选择是扩展你正在使用的首选项。例如,如果您正在使用大量的复选框,只需扩展复选框首选项,并将逻辑添加到重写的方法中即可。根据我的经验,这大大减少了代码,并使逻辑非常容易遵循。如果您需要了解某个东西是如何工作的,或者需要“黑”一些东西,您可以在grepcode.com上看到原始源代码。
https://stackoverflow.com/questions/9719541
复制相似问题