Toast不会在Android DatePickerDialog

时间:2018-03-01 00:24:02

标签: firebase recycler-adapter firebaseui

我有pickDateTime函数,它限制用户选择过去的时间。当前时间 - 最小值"时间允许。

这是功能:

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();
}

这是班级:

public class NewMissionUser extends AppCompatActivity implements PopupMenu.OnMenuItemClickListener, GmapFragmentNewMission.TextClicked

问题是,Toast不会出现在这些尝试中的任何一个。 Log DOES出现,在调试中我看到代码到达这一点并且isPast函数的行为符合预期。

为什么Toast不会上来?感谢。

1 个答案:

答案 0 :(得分:1)

您错过了show() Toast

的来电
Toast.makeText(getApplicationContext(), "...",Toast.LENGTH_LONG).show();