open date picker on button click event
btn.setOnClickListener(new OnClickListener() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
// Launch Date Picker Dialog
DatePickerDialog dpd = new DatePickerDialog(
SurveyMain.this,
new DatePickerDialog.OnDateSetListener() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onDateSet(
DatePicker view, int year,
int monthOfYear,
int dayOfMonth) {
GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.DATE, 1);
datetomoroow = gc.getTime();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH,
monthOfYear);
c.set(Calendar.DAY_OF_MONTH,
dayOfMonth);
SimpleDateFormat sdf = new SimpleDateFormat(
"dd MMM yyyy");
btnpostpond.setText(""
+ sdf.format(c
.getTime()));
}
}, mYear, mMonth, mDay);
// dpd.getDatePicker().setMinDate( //-----it means block past // date
// System.currentTimeMillis() - 1000);
dpd.show();
}
});
dialog.show();
}
});
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
// Launch Date Picker Dialog
DatePickerDialog dpd = new DatePickerDialog(
SurveyMain.this,
new DatePickerDialog.OnDateSetListener() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onDateSet(
DatePicker view, int year,
int monthOfYear,
int dayOfMonth) {
GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.DATE, 1);
datetomoroow = gc.getTime();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH,
monthOfYear);
c.set(Calendar.DAY_OF_MONTH,
dayOfMonth);
SimpleDateFormat sdf = new SimpleDateFormat(
"dd MMM yyyy");
btnpostpond.setText(""
+ sdf.format(c
.getTime()));
}
}, mYear, mMonth, mDay);
// dpd.getDatePicker().setMinDate( //-----it means block past // date
// System.currentTimeMillis() - 1000);
dpd.show();
}
});
dialog.show();
}
});
Comments
Post a Comment