如何添加计时器以在应用程序打开时更改应用程序的背景 ....这是一个更改背景和图像视图的代码,但不会自动更改....如何执行此操作以使此框架刷新????
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mMainView = inflater.inflate(R.layout.fragment_weather, container, false);
changebackground = (RelativeLayout)mMainView.findViewById(R.id.weatherbackground);
celestials=(ImageView)mMainView.findViewById(R.id.celestial);
temperature = (TextView)mMainView.findViewById(R.id.temperature);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.set(Calendar.HOUR_OF_DAY, 6);
cal.set(Calendar.MINUTE, 00);
cal.set(Calendar.SECOND, 0);
long morning_start = cal.getTimeInMillis();
cal.set(Calendar.HOUR_OF_DAY, 18);
cal.set(Calendar.MINUTE, 30);
cal.set(Calendar.SECOND, 0);
long morning_end = cal.getTimeInMillis();
long now = System.currentTimeMillis();
if(now > morning_start && now < morning_end)
{
changebackground.setBackgroundResource(R.drawable.day);
celestials.setImageResource(R.drawable.sun);
}
else
{
changebackground.setBackgroundResource(R.drawable.night);
celestials.setImageResource(R.drawable.moon);
}
return mMainView;
}
答案 0 :(得分:0)
您可以通过主活动中的定义处理程序来执行此操作,该处理程序将在特定时间触发操作,例如
import jenkins.model.Jenkins
Jenkins.instance.computers.each() { c ->
if(c instanceof hudson.slaves.SlaveComputer) {
// <Find out agent protocol of c>
};
}
另请在onCreate
中写下以下一行Handler mHandler = new Handler();
Runnable mRunnableUpdatePro = new Runnable() {
@Override
public void run() {
mHandler.removeCallbacks(mRunnableUpdatePro);
mHandler.postDelayed(mRunnableUpdatePro, TIME_TO_UPDATE_BACKGROUND);
// updateYourPicAndTheameHere();
}
};