I have pickDateTime function, that restricts the user of choosing times that are in past. Current time - is the "minimum" time allowed.
This is the function:
public void pickDateTime(View view) {
Calendar c = Calendar.getInstance();
currentYear = c.get(Calendar.YEAR);
currentMonth = c.get(Calendar.MONTH);
currentDay = c.get(Calendar.DAY_OF_MONTH);
currentHour = c.get(Calendar.HOUR_OF_DAY);
currentMinute = c.get(Calendar.MINUTE);
DatePickerDialog datePickerDialog = new DatePickerDialog(NewMissionUser.this
, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
Log.d(TAG,"Chose: year: " + year + " , month: " + (month+1) + " day: " + day);
missionYear = year;
missionMonth = (month+1);
missionDay = day;
TimePickerDialog timePickerDialog = new TimePickerDialog(NewMissionUser.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
missionTime = missionDay+"/"+missionMonth+"/"+missionYear + " " +hourOfDay + ":" + minute;
Log.d(TAG,"missionTime: " + missionTime);
if (isPast(missionTime)){
Log.d(TAG,"mission time in past!");
Toast.makeText(getApplicationContext(), "APP Mission inserted in past, ignoring date, default date is now.",Toast.LENGTH_LONG);
Toast.makeText(NewMissionUser.this, "Mission inserted in past, ignoring date, default date is now.",Toast.LENGTH_LONG);
Toast.makeText(getBaseContext(), "BASE Mission inserted in past, ignoring date, default date is now.",Toast.LENGTH_LONG);
missionTime = currentDay+"/"+currentMonth+"/"+currentYear + " " +currentHour + ":" + currentMinute;
}
}
},currentHour, currentMinute, true);
timePickerDialog.show();
}
},currentYear, currentMonth, currentDay);
datePickerDialog.show();
}
This is the class:
public class NewMissionUser extends AppCompatActivity implements PopupMenu.OnMenuItemClickListener, GmapFragmentNewMission.TextClicked
The problem is, that the Toast won't show up in either of these tries. The Log DOES appear, and in debug I see that the code reaches this point and isPast function is behaving as expected.
Why the Toast won't come up? Thanks.
You're missing the call to show() the Toast
:
Toast.makeText(getApplicationContext(), "...",Toast.LENGTH_LONG).show();