how to add timer to change background of an app in an app while it is open ....This is a code that changes the background and imageview but doesn't change it automatically.... how to do it so that this frame refreshes????
@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;
}