尝试显示/隐藏我创建的图像,以便在时间到来时显示太阳,并在时间到达时显示月亮
我尝试了2个代码,但它仅以am / pm格式显示pm图像
代码编号
Calendar mCalendar = Calendar.getInstance();
mCalendar.isSet(Calendar.HOUR_OF_DAY);
mCalendar.isSet(Calendar.MINUTE);
if (mCalendar.get(Calendar.AM_am) == Calendar.AM)
image_am.setVisibility(View.VISIBLE);
image_pm.setVisibility(View.INVISIBLE);
if (mCalendar.get(Calendar.PM_pm) == Calendar.PM)
image_pm.setVisibility(View.VISIBLE);
image_am.setVisibility(View.INVISIBLE);
SimpleDateFormat sdf1 = new SimpleDateFormat("d/M/yy h:m:s a");
String strdate1 = sdf1.format(mCalendar.getTime());
代码二
Calendar mCalendar = Calendar.getInstance();
mCalendar.isSet(Calendar.HOUR_OF_DAY);
mCalendar.isSet(Calendar.MINUTE);
if (mCalendar.get(Calendar.AM_PM) == Calendar.AM)
AM_PM= R.drawable.sun;
if (mCalendar.get(Calendar.AM_PM) == Calendar.PM)
AM_PM= R.drawable.moon;
SimpleDateFormat sdf1 = new SimpleDateFormat("d/M/yy h:m:s a");
String strdate1 = sdf1.format(mCalendar.getTime());
Imageview.setBackgroundResource(AM_PM);
有没有办法让这些代码以am / pm格式显示和隐藏太阳/月亮图像,因为它只显示pm(月亮)图像?