我的应用程序中有一个简单的if-else语句,但它不起作用。如果我在Spinner中选择“ day ” ,则只能编辑那一天。它不起作用,因为仍然可以编辑所有日子。有人能告诉我为什么吗?
final String[] items={"Day","Date","Time","Location"};
mSpin2.setOnItemSelectedListener(
new OnItemSelectedListener() {
@Override
public void onItemSelected(
AdapterView<?> parent2, View view, int pos, long id
) {
String strsel=items[pos];
if(strsel.equalsIgnoreCase("Day")) {
btnChangeDate.setFocusable(false);
btnChangeDate.setEnabled(false);
//btnChangeDate.setClickable(false);
btnChangeTime.setFocusable(false);
btnChangeTime.setEnabled(false);
//btnChangeTime.setClickable(false);
mLatitude.setFocusable(false);
mLatitude.setEnabled(false);
mLongitude.setFocusable(false);
mLongitude.setEnabled(false);
} else {
mMonday.setFocusable(true);
mMonday.setEnabled(true);
mTuesday.setFocusable(true);
mTuesday.setEnabled(true);
mWednesday.setFocusable(true);
mWednesday.setEnabled(true);
mThursday.setFocusable(true);
mThursday.setEnabled(true);
mFriday.setFocusable(true);
mFriday.setEnabled(true);
mSaturday.setFocusable(true);
mSaturday.setEnabled(true);
mSunday.setFocusable(true);
mSunday.setEnabled(true);
}
String strsel2=items[pos];
if(strsel2.equalsIgnoreCase("Date")) {
mMonday.setFocusable(false);
mMonday.setEnabled(false);
mTuesday.setFocusable(false);
mTuesday.setEnabled(false);
mWednesday.setFocusable(false);
mWednesday.setEnabled(false);
mThursday.setFocusable(false);
mThursday.setEnabled(false);
mFriday.setFocusable(false);
mFriday.setEnabled(false);
mSaturday.setFocusable(false);
mSaturday.setEnabled(false);
mSunday.setFocusable(false);
mSunday.setEnabled(false);
btnChangeTime.setFocusable(false);
btnChangeTime.setEnabled(false);
//btnChangeTime.setClickable(false);
mLatitude.setFocusable(false);
mLatitude.setEnabled(false);
mLongitude.setFocusable(false);
mLongitude.setEnabled(false);
} else {
btnChangeDate.setFocusable(true);
btnChangeDate.setEnabled(true);
}
String strsel3=items[pos];
if(strsel3.equalsIgnoreCase("Time")) {
mMonday.setFocusable(false);
mMonday.setEnabled(false);
mTuesday.setFocusable(false);
mTuesday.setEnabled(false);
mWednesday.setFocusable(false);
mWednesday.setEnabled(false);
mThursday.setFocusable(false);
mThursday.setEnabled(false);
mFriday.setFocusable(false);
mFriday.setEnabled(false);
mSaturday.setFocusable(false);
mSaturday.setEnabled(false);
mSunday.setFocusable(false);
mSunday.setEnabled(false);
btnChangeDate.setFocusable(false);
btnChangeDate.setEnabled(false);
//btnChangeDate.setClickable(false);
mLatitude.setFocusable(false);
mLatitude.setEnabled(false);
mLongitude.setFocusable(false);
mLongitude.setEnabled(false);
} else {
btnChangeTime.setFocusable(true);
btnChangeTime.setEnabled(true);
}
String strsel4=items[pos];
if(strsel.equalsIgnoreCase("Location")) {
mMonday.setFocusable(false);
mMonday.setEnabled(false);
mTuesday.setFocusable(false);
mTuesday.setEnabled(false);
mWednesday.setFocusable(false);
mWednesday.setEnabled(false);
mThursday.setFocusable(false);
mThursday.setEnabled(false);
mFriday.setFocusable(false);
mFriday.setEnabled(false);
mSaturday.setFocusable(false);
mSaturday.setEnabled(false);
mSunday.setFocusable(false);
mSunday.setEnabled(false);
btnChangeDate.setFocusable(false);
btnChangeDate.setEnabled(false);
//btnChangeDate.setClickable(false);
btnChangeTime.setFocusable(false);
btnChangeTime.setEnabled(false);
//btnChangeTime.setClickable(false);
} else {
//mLatitude.setFocusable(true);
mLatitude.setEnabled(true);
//mLongitude.setFocusable(true);
mLongitude.setEnabled(true);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {}
}
);