我对Android很新,我想改变(我知道如何动态设置它......)Textview在一段时间后动态地运行,但在此期间保持文本发布,除非用户更改或者如果我的计划已达到某一天。
基本上我有用户输入日期然后我希望我的程序计算天数,只要用户和我的程序介入textview它将显示相同的文本和背景颜色,直到相反的行动
这是我的代码:
String CurrentDate = new SimpleDateFormat("dd/MM/yyyy").format(new Date());
String FinalDate = TvDateOfService.getText().toString();
SimpleDateFormat dates = new SimpleDateFormat("dd/MM/yyyy");
Date dateinput;
Date datetwra;
//Setting dates
try {
dateinput = dates.parse(FinalDate);
datetwra = dates.parse(CurrentDate);
//Comparing dates
long difference = Math.abs(dateinput.getTime() - datetwra.getTime());
long differenceDates = difference / (24 * 60 * 60 * 1000);
//Convert long to String
String dayDifference = Long.toString(differenceDates);
//Calendar Instance to Add 89 Days for Service Period Between Dates!!
Calendar cal1 = Calendar.getInstance();
cal1.add(Calendar.DATE, 90);
Date ServicePeriod = cal1.getTime();
Calendar cal2 = Calendar.getInstance();
cal2.add(Calendar.DATE, 80);
Date DaysBeforeEnd = cal2.getTime();
do {
tvStatus.setBackground(getApplicationContext().getResources().getDrawable(R.drawable.textview_backround_green));
}while (dateinput.before(DaysBeforeEnd));
do {
tvStatus.setText("something");
tvStatus.setBackground(getApplicationContext().getResources().getDrawable(R.drawable.textview_backround_yellow));
}while (dateinput.after(DaysBeforeEnd));
do {
tvStatus.setText("something else");
tvStatus.setBackground(getApplicationContext().getResources().getDrawable(R.drawable.textview_backround_red));
}while (dateinput.after(ServicePeriod));
答案 0 :(得分:0)
看起来您正在尝试使用for循环并等待一定天数 - 如果您使用AlarmManager,这对手机的电池最有利
https://developer.android.com/trai.../scheduling/alarms.html