I am trying to implement something similar to a timesheet so what I basically need is when I select one particular date from the datepicker dialog then I want to display a textview which contains the days of the whole week in which the selected date is present.
Below is what I have implemented to select a date from the date picket dialog.
Calendar cal = Calendar.getInstance();
EditText edt1;
String dateFormat = "dd/MM/yyyy";
final DatePickerDialog.OnDateSetListener date1 = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, monthOfYear);
cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel1();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timesheet_form);
edt1=(EditText)findViewById(R.id.editText1);
edt1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new DatePickerDialog(TimesheetForm.this, date1, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)).show();
}
});
}
private void updateLabel1() {
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.US);
edt1.setText(sdf.format(fromCalendar.getTime()));
}
The above code returns the selected date from the dialog but there seems to be no method to return the days of the whole week.