I am trying to add a calendar to my application, my code is as follows:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calendar);
btn_fecha = (Button)findViewById(R.id.btn_fecha);
btn_hora = (Button)findViewById(R.id.btn_hora);
btn_next_fecha = (Button)findViewById(R.id.btn_next_fecha);
eFecha = (EditText)findViewById(R.id.eFecha);
eHora = (EditText)findViewById(R.id.eHora);
btn_fecha.setOnClickListener(this);
btn_hora.setOnClickListener(this);
}
@Override
protected void onResume() {
super.onResume();
btn_next_fecha = (Button)findViewById(R.id.btn_next_fecha);
btn_next_fecha.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent btn_next_fecha = new Intent(SelectDayActivity.this, DatosAutoActivity.class);
startActivity(btn_next_fecha);
}
});
}
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onClick(View v) {
if (v==btn_fecha){
final Calendar c = Calendar.getInstance();
dia = c.get(Calendar.DAY_OF_MONTH);
mes = c.get(Calendar.MONTH);
ano = c.get(Calendar.YEAR);
DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
eFecha.setText(dayOfMonth+"/"+(month+1)+"/"+year);
}
}
,dia, mes, ano);
datePickerDialog.show();
}
My code works, however, when the calendar appears it shows the year 1900 and I would like it to appear today's date (the current date that the cell phone has)
Could you support me to do that? Thanks