Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: date picker from calendar popdown

In my app user should select a date by clicking on Edit Text, for that currently i'm using a date picker dialog and its working good but its like opening another dialog and all. so i thought of showing it like pop down menu, checkout the pic. please help me to achieve this!

Calendar pic

like image 758
Jarvis Avatar asked Mar 21 '23 05:03

Jarvis


1 Answers

Try this @Jarvis

 public class MainActivity extends Activity {

 EditText date;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main2);
    date=(EditText)findViewById(R.id.date);

    date.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                new DatePickerDialog(ProximityActivity.this, dateD, myCalendar
                        .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
                        myCalendar.get(Calendar.DAY_OF_MONTH)).show();
            }
        });
}
Calendar myCalendar = Calendar.getInstance();

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

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

};

  private void updateLabel() {

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

        date.setText(sdf.format(myCalendar.getTime()));
  }

}

like image 72
M D Avatar answered Apr 01 '23 12:04

M D