0
我在Android开发中做了一些代码更改,以使我的编码更加准确。 我有我的布局中的所有星期几天的7个TextViews,我已经通过id为所有这些TextView找到了查看。代码优化问题
要求是,当用户单击来自该7个TextView的任何人时,一次只能选择一个TextView。
所以,我有一些如下重复的代码,检查出来:
case R.id.txt_sunday:
if (Prefrences.getBooleanValue(mContext, D_SUN)) {
doUnSelect(D_SUN, mTxtSunday);
} else {
Prefrences.setBooleanValue(mContext, HH_FILTER, true);
selectedDay = "0";
Prefrences.setBooleanValue(mContext, D_SUN, true);
Prefrences.setBooleanValue(mContext, D_MON, false);
Prefrences.setBooleanValue(mContext, D_TUE, false);
Prefrences.setBooleanValue(mContext, D_WED, false);
Prefrences.setBooleanValue(mContext, D_THR, false);
Prefrences.setBooleanValue(mContext, D_FRI, false);
Prefrences.setBooleanValue(mContext, D_SAT, false);
mTxtSunday.setBackgroundResource(R.color.colorAppDefault);
mTxtSunday.setTextColor(getResources().getColor(R.color.white));
mTxtMonday.setBackgroundResource(R.color.white);
mTxtMonday.setTextColor(getResources().getColor(R.color.black));
mTxtTuesday.setBackgroundResource(R.color.white);
mTxtTuesday.setTextColor(getResources().getColor(R.color.black));
mTxtWednesday.setBackgroundResource(R.color.white);
mTxtWednesday.setTextColor(getResources().getColor(R.color.black));
mTxtThrusday.setBackgroundResource(R.color.white);
mTxtThrusday.setTextColor(getResources().getColor(R.color.black));
mTxtFriday.setBackgroundResource(R.color.white);
mTxtFriday.setTextColor(getResources().getColor(R.color.black));
mTxtSaturday.setBackgroundResource(R.color.white);
mTxtSaturday.setTextColor(getResources().getColor(R.color.black));
}
break;
如,你可以看到在上面的代码。我已经采取了开关的情况下处理我的所有七个TextViews的点击,以上情况适用于SUNDAY。 所以,现在,您可能会明白,我在星期一至星期六剩余的日子里完成了相同的工作。正确。
现在,我必须优化我的其他部分,因为我优化了我的if部分在上面的代码。
怎么样?
在此先感谢。
什么是'mTxtSunday'在你的代码,按钮,textview? –
雅,其实它的TextView ..但是,没关系。按钮和textview的概念是相同的。为我的错误而打招呼。将其视为TextView。 –
什么是'D_SUN'是它的'int','String'的东西? –