Currently I am using code below and I can get current date to be dispalyed in Text field. However I have no idea how to display selected date.
I also used DatePicker and it displays selected date fine, however I would prefer CalendarView. Thanks
Calendar c = Calendar.getInstance();
SimpleDateFormat ss = new SimpleDateFormat("dd-MM-yyyy");
Date date = new Date();
String currentdate= ss.format(date);
TextView editText = (TextView) this.findViewById(R.id.textfield1);
editText.setText(currentdate);
Show activity on this post. Calendar date = Calendar. getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd"); curDate = sdf. format(date.
This article shows how to create an android application for displaying the Calendar using CalendarView. It also provides the selection of the current date and displaying the date. The setOnDateChangeListener Interface is used which provide onSelectedDayChange method.
1. getDate(): This method is used to get the selected date of CalendarView in milliseconds since January 1, 1970 00:00:00 in user's preferred time zone.
in onCreate :
CalendarView v = new CalendarView( this );
v.setOnDateChangeListener( new CalendarView.OnDateChangeListener() {
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
this.calendar = new GregorianCalendar( year, month, dayOfMonth );
}//met
});
CalendarView view = new CalendarView(this);
setContentView(view);
view.setOnDateChangeListener(new OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView arg0, int year, int month,
int date) {
Toast.makeText(getApplicationContext(),date+ "/"+month+"/"+year,4000).show();
}
});
This will display the user selected date.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With