since in Android 7.0 nougat the datepicker in spinner mode does not work opt to put the datepicker in a dialog. this is invoked with a button in the activity and executed from a java class and it is sent a return method in which I return the date and set it in the same textView where it was invoked, in a few words I click open the dialog, I select the date I want to accept and set the date in the dialog all right there, my problem is that by clicking the datepicker I get the date today, I found the datepicker.init () method which accepts 4 parameters that are the int of day, month and year, I need to return the data I emptied in the datePicker and send them to this dialog. but I can not do it any help will be very grateful, I can not do the datepicker in another way since it does not work with the spinner in android 7 I leave my code Here it is invoked by clicking on a textView:
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_index);
dtbAlert = (TextView) findViewById(R.id.datepickerButtonAlert);
dtbAlert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new CuadroDialog(context, IndexActivity.this);
}
});
implements to implements CuadroDialog.finalizaDialogo
JAVA CLASS:
public class CuadroDialog { public interface finalizesDialog {
void traerFecha(int dia, int mes, int ano);
}
private finalizaDialogo interfaz;
public CuadroDialog(Context context, finalizaDialogo actividad) {
interfaz = actividad;
final Dialog dialog = new Dialog(context);
dialog.getContext();
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(true);
dialog.setContentView(R.layout.dialog_date_picker);
final DatePicker datePicker = (DatePicker) dialog.findViewById(R.id.date_datePicker);
int day = 5; --------> harcode los valores para ver si funcionaba
int year = 1990;-----> aquí quiero meter el valor del textview
int mes = 8;---------> que recuperaria del activity
datePicker.init(year, day, mes, null);
TextView btnCancel = (TextView) dialog.findViewById(R.id.botonCancel);
TextView btnGone = (TextView) dialog.findViewById(R.id.botonGone);
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
btnGone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
interfaz.traerFecha(datePicker.getDayOfMonth(), datePicker.getMonth() + 1, datePicker.getYear());
dialog.dismiss();
}
});
dialog.show();
}
}