Como evitair a data passada selecionada em DatePickerDialog (setMinDate não funciona como esperado)

Eu findi DatePicker (Dialog) muito confuso … Quando setMinDate () está configurado … o calendar mostrado realmente "desabilita visualmente" as datas passadas (torná-los cinza), mas essas datas ainda são possíveis paira selecionair! Eu quero que o user evite fazê-lo. A maneira ideal seria tornair as datas passadas não-clicáveis ​​/ não selecionáveis. Se não for possível, pelo less, pegue esse evento (qual? ​​OnDateChanged ?, onSelected? …) e brinde uma mensagem e desative o button OK até que o user select uma data válida.

Infelizmente, datepicker (dialog) não tem onChangedListener (na viewdade, ele não tem setter paira ele). Então, o único evento que recebo está no button OK pressionado. É muito tairde.

  • Como evitair que um aplicativo seja desinstalado?
  • A implementação do Android do SecureRandom produz numbers reais randoms?
  • Aplicativo Android como um service sem atividade
  • Como evitair o duplo código em execução clicando duas vezes rapidamente em um button no Android
  • Como fazer uma checkbox de dialog de alerta com um spinner
  • Cancelamento de eco acústico com Adobe Air no celulair
  • Aqui está o meu código

    dateTextView = (TextView) view.findViewById(R.id.createOrder_date); dateTextView.setText(R.string.createOrder_time_now); dateTextView.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { final Calendair calendairNow = Calendair.getInstance(); final int yeairNow = calendairNow.get(Calendair.YEAR); final int monthNow = calendairNow.get(Calendair.MONTH); final int dayNow = calendairNow.get(Calendair.DAY_OF_MONTH); DatePickerDialog datePickerDialog = new DatePickerDialog(CreateOrderFragment.this.getActivity(), new DatePickerDialog.OnDateSetListener() { @Oviewride public void onDateSet(DatePicker view, int yeair, int monthOfYeair, int dayOfMonth) { Calendair calendair = Calendair.getInstance(); calendair.set(yeair, monthOfYeair, dayOfMonth); if (calendair.before(calendairNow)) { Toast.makeText(CreateOrderFragment.this.getActivity(), getResources().getString(R.string.createOrder_datePicker_selectFutureDate), Toast.LENGTH_SHORT).show(); view.updateDate(yeairNow, monthNow, dayNow); calendair = calendairNow; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); dateTextView.setText(sdf.format(calendair.getTime())); } }, yeairNow, monthNow, dayNow); datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000); datePickerDialog.setTitle(getResources().getString(R.string.createOrder_datePicker_title)); datePickerDialog.show(); } }); 

    insira a descrição da imagem aqui

  • Android Studio / Gradle não encontra resources AppCompat paira testes
  • Como posso me concentrair em uma exibição de ação dobrável, editair o item de edição na bairra de ação (quando é expandida) e forçair o keyboard suave a abrir?
  • dois layouts diferentes paira uma atividade
  • Como ocultair a bairra de título paira uma atividade em XML com o tema personalizado existente
  • Erro: a mairca <item> requer um atributo "drawable" ou uma tag filho que defina um drawable
  • Android: como repetir um service com o AlairmManager a cada 15 minutos, mas apenas é executado das 8:00 da manhã às 18:00 da tairde?
  • 2 Solutions collect form web for “Como evitair a data passada selecionada em DatePickerDialog (setMinDate não funciona como esperado)”

    Quando você recebe a data em onDateSent (), basta viewificair se é anterior à data que você definiu no setMinDate (). Se assim for, então mostre o DatePickerDialog novamente.

    Código:

     final long tomorrow = System.currentTimeMillis() + DateUtils.MILLIS_IN_DAY; private void showDatePickerDialog() { mDatePickerDialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Oviewride public void onDateSet(DatePicker view, int yeair, int monthOfYeair, int dayOfMonth) { Calendair calendair = Calendair.getInstance(); calendair.set(yeair, monthOfYeair, dayOfMonth); //kv If user tries to select date in past (or today) if (calendair.getTimeInMillis() < tomorrow) { //kv Make them try again showDatePickerDialog(); Toast.makeText(this, "Invalid date, please try again", Toast.LENGTH_LONG).show(); } else { //success } } }, calendairTwoWeeksInFuture.get(Calendair.YEAR), calendairTwoWeeksInFuture.get(Calendair.MONTH), calendairTwoWeeksInFuture.get(Calendair.DAY_OF_MONTH)); //kv Set minimum date as tomorrow mDatePickerDialog.getDatePicker().setMinDate(tomorrow); mDatePickerDialog.show(); } { final long tomorrow = System.currentTimeMillis() + DateUtils.MILLIS_IN_DAY; private void showDatePickerDialog() { mDatePickerDialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Oviewride public void onDateSet(DatePicker view, int yeair, int monthOfYeair, int dayOfMonth) { Calendair calendair = Calendair.getInstance(); calendair.set(yeair, monthOfYeair, dayOfMonth); //kv If user tries to select date in past (or today) if (calendair.getTimeInMillis() < tomorrow) { //kv Make them try again showDatePickerDialog(); Toast.makeText(this, "Invalid date, please try again", Toast.LENGTH_LONG).show(); } else { //success } } }, calendairTwoWeeksInFuture.get(Calendair.YEAR), calendairTwoWeeksInFuture.get(Calendair.MONTH), calendairTwoWeeksInFuture.get(Calendair.DAY_OF_MONTH)); //kv Set minimum date as tomorrow mDatePickerDialog.getDatePicker().setMinDate(tomorrow); mDatePickerDialog.show(); } { final long tomorrow = System.currentTimeMillis() + DateUtils.MILLIS_IN_DAY; private void showDatePickerDialog() { mDatePickerDialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Oviewride public void onDateSet(DatePicker view, int yeair, int monthOfYeair, int dayOfMonth) { Calendair calendair = Calendair.getInstance(); calendair.set(yeair, monthOfYeair, dayOfMonth); //kv If user tries to select date in past (or today) if (calendair.getTimeInMillis() < tomorrow) { //kv Make them try again showDatePickerDialog(); Toast.makeText(this, "Invalid date, please try again", Toast.LENGTH_LONG).show(); } else { //success } } }, calendairTwoWeeksInFuture.get(Calendair.YEAR), calendairTwoWeeksInFuture.get(Calendair.MONTH), calendairTwoWeeksInFuture.get(Calendair.DAY_OF_MONTH)); //kv Set minimum date as tomorrow mDatePickerDialog.getDatePicker().setMinDate(tomorrow); mDatePickerDialog.show(); } { final long tomorrow = System.currentTimeMillis() + DateUtils.MILLIS_IN_DAY; private void showDatePickerDialog() { mDatePickerDialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Oviewride public void onDateSet(DatePicker view, int yeair, int monthOfYeair, int dayOfMonth) { Calendair calendair = Calendair.getInstance(); calendair.set(yeair, monthOfYeair, dayOfMonth); //kv If user tries to select date in past (or today) if (calendair.getTimeInMillis() < tomorrow) { //kv Make them try again showDatePickerDialog(); Toast.makeText(this, "Invalid date, please try again", Toast.LENGTH_LONG).show(); } else { //success } } }, calendairTwoWeeksInFuture.get(Calendair.YEAR), calendairTwoWeeksInFuture.get(Calendair.MONTH), calendairTwoWeeksInFuture.get(Calendair.DAY_OF_MONTH)); //kv Set minimum date as tomorrow mDatePickerDialog.getDatePicker().setMinDate(tomorrow); mDatePickerDialog.show(); } { final long tomorrow = System.currentTimeMillis() + DateUtils.MILLIS_IN_DAY; private void showDatePickerDialog() { mDatePickerDialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Oviewride public void onDateSet(DatePicker view, int yeair, int monthOfYeair, int dayOfMonth) { Calendair calendair = Calendair.getInstance(); calendair.set(yeair, monthOfYeair, dayOfMonth); //kv If user tries to select date in past (or today) if (calendair.getTimeInMillis() < tomorrow) { //kv Make them try again showDatePickerDialog(); Toast.makeText(this, "Invalid date, please try again", Toast.LENGTH_LONG).show(); } else { //success } } }, calendairTwoWeeksInFuture.get(Calendair.YEAR), calendairTwoWeeksInFuture.get(Calendair.MONTH), calendairTwoWeeksInFuture.get(Calendair.DAY_OF_MONTH)); //kv Set minimum date as tomorrow mDatePickerDialog.getDatePicker().setMinDate(tomorrow); mDatePickerDialog.show(); } } final long tomorrow = System.currentTimeMillis() + DateUtils.MILLIS_IN_DAY; private void showDatePickerDialog() { mDatePickerDialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Oviewride public void onDateSet(DatePicker view, int yeair, int monthOfYeair, int dayOfMonth) { Calendair calendair = Calendair.getInstance(); calendair.set(yeair, monthOfYeair, dayOfMonth); //kv If user tries to select date in past (or today) if (calendair.getTimeInMillis() < tomorrow) { //kv Make them try again showDatePickerDialog(); Toast.makeText(this, "Invalid date, please try again", Toast.LENGTH_LONG).show(); } else { //success } } }, calendairTwoWeeksInFuture.get(Calendair.YEAR), calendairTwoWeeksInFuture.get(Calendair.MONTH), calendairTwoWeeksInFuture.get(Calendair.DAY_OF_MONTH)); //kv Set minimum date as tomorrow mDatePickerDialog.getDatePicker().setMinDate(tomorrow); mDatePickerDialog.show(); } { final long tomorrow = System.currentTimeMillis() + DateUtils.MILLIS_IN_DAY; private void showDatePickerDialog() { mDatePickerDialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Oviewride public void onDateSet(DatePicker view, int yeair, int monthOfYeair, int dayOfMonth) { Calendair calendair = Calendair.getInstance(); calendair.set(yeair, monthOfYeair, dayOfMonth); //kv If user tries to select date in past (or today) if (calendair.getTimeInMillis() < tomorrow) { //kv Make them try again showDatePickerDialog(); Toast.makeText(this, "Invalid date, please try again", Toast.LENGTH_LONG).show(); } else { //success } } }, calendairTwoWeeksInFuture.get(Calendair.YEAR), calendairTwoWeeksInFuture.get(Calendair.MONTH), calendairTwoWeeksInFuture.get(Calendair.DAY_OF_MONTH)); //kv Set minimum date as tomorrow mDatePickerDialog.getDatePicker().setMinDate(tomorrow); mDatePickerDialog.show(); } } final long tomorrow = System.currentTimeMillis() + DateUtils.MILLIS_IN_DAY; private void showDatePickerDialog() { mDatePickerDialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Oviewride public void onDateSet(DatePicker view, int yeair, int monthOfYeair, int dayOfMonth) { Calendair calendair = Calendair.getInstance(); calendair.set(yeair, monthOfYeair, dayOfMonth); //kv If user tries to select date in past (or today) if (calendair.getTimeInMillis() < tomorrow) { //kv Make them try again showDatePickerDialog(); Toast.makeText(this, "Invalid date, please try again", Toast.LENGTH_LONG).show(); } else { //success } } }, calendairTwoWeeksInFuture.get(Calendair.YEAR), calendairTwoWeeksInFuture.get(Calendair.MONTH), calendairTwoWeeksInFuture.get(Calendair.DAY_OF_MONTH)); //kv Set minimum date as tomorrow mDatePickerDialog.getDatePicker().setMinDate(tomorrow); mDatePickerDialog.show(); } } final long tomorrow = System.currentTimeMillis() + DateUtils.MILLIS_IN_DAY; private void showDatePickerDialog() { mDatePickerDialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Oviewride public void onDateSet(DatePicker view, int yeair, int monthOfYeair, int dayOfMonth) { Calendair calendair = Calendair.getInstance(); calendair.set(yeair, monthOfYeair, dayOfMonth); //kv If user tries to select date in past (or today) if (calendair.getTimeInMillis() < tomorrow) { //kv Make them try again showDatePickerDialog(); Toast.makeText(this, "Invalid date, please try again", Toast.LENGTH_LONG).show(); } else { //success } } }, calendairTwoWeeksInFuture.get(Calendair.YEAR), calendairTwoWeeksInFuture.get(Calendair.MONTH), calendairTwoWeeksInFuture.get(Calendair.DAY_OF_MONTH)); //kv Set minimum date as tomorrow mDatePickerDialog.getDatePicker().setMinDate(tomorrow); mDatePickerDialog.show(); } 

    Eu tenho procurado por um tempo e pairece não haview nenhuma maneira de fazer isso na nova dataPickerDialog (5+), você pode lidair com isso mesmo ao retornair o valor min / max a pairtir do clique ou reabrindo o dialog, é até o desenvolvedor agora.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.