Click here to Skip to main content
15,886,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
Calendar myCalendar = Calendar.getInstance();

DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear,
        int dayOfMonth) {
    // TODO Auto-generated method stub
        myCalendar.set(Calendar.YEAR, year);
        myCalendar.set(Calendar.MONTH, monthOfYear);
        myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
        updateLabel();
    }

};

edittext.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        new DatePickerDialog(new_split.this, date, myCalendar
            .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
            myCalendar.get(Calendar.DAY_OF_MONTH)).show();
// this code below is not hiding calendar,stopping the application
if (Build.VERSION.SDK_INT >= 11) {
    datePickerDialog.getDatePicker().setCalendarViewShown(false);
}


    }
});

private void updateLabel() {

String myFormat = "MM/dd/yy"; //In which you need put here
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);

edittext.setText(sdf.format(myCalendar.getTime()));
}
Posted
Updated 5-Sep-13 23:50pm
v2
Comments
Ganesh KP 7-Sep-13 2:17am    
Hi, I am really confused with your question. What do you want to do exactly? You can have buttons of Ok and Cancel to the date picker to close the calendar when ever you does not require the datepicker or calendar.

If this is not the your query, please specify it clearly what do you want to achieve?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900