in my app i can set an alarm for any the days of the week, i want to display a toast with the time until the next alarm, i set a value for every day:
String[] str = new String[7];
str[0] = getResources().getString(R.string.weeks_sunday);
str[1] = getResources().getString(R.string.weeks_monday);
str[2] = getResources().getString(R.string.weeks_tuesday);
str[3] = getResources().getString(R.string.weeks_wednesday);
str[4] = getResources().getString(R.string.weeks_thursday);
str[5] = getResources().getString(R.string.weeks_friday);
str[6] = getResources().getString(R.string.weeks_Saturday);
weeks = str;
This what i do to calculate the time to the next alarm, but i dont know how to know the close day
String substr = ":";
String before = aTime.substring(0, aTime.indexOf(substr));
int bef = Integer.parseInt(before);
String after = aTime.substring(aTime.indexOf(substr) + substr.length());
int aft = Integer.parseInt(after);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int dayy = c.get(Calendar.DAY_OF_MONTH);
GregorianCalendar date = new GregorianCalendar();
long currentTime = date.getTimeInMillis();
GregorianCalendar calendar = new GregorianCalendar();
calendar.set(year, month, 22, bef, aft, 0);
long difference = calendar.getTimeInMillis()-currentTime;
long x = difference / 1000;
long seconds = x % 60;
x /= 60;
long minutes = x % 60;
x /= 60;
long hours = x % 24;
x /= 24;
long days = x;
if(hours == 1){
Toast.makeText(AddAlarmActivity.this, "Alarm set for " + days + " days, " + hours + " hour and " + minutes + " minutes from now", Toast.LENGTH_LONG).show();
}else if(hours >= 2){
Toast.makeText(AddAlarmActivity.this, "Alarm set for " + days + " days, " + hours + " hours and " + minutes + " minutes from now", Toast.LENGTH_LONG).show();