Skip to main content

Posts

Showing posts from March, 2017

DatePickers in Android

DatePicker is a view which lets the user select a date showing a calendar or 3 spinners for dd, mm and yy. Let us see how to use this. Easy Method: To use a DatePicker you can use DatePickerDialog. This can be created and shown programmatically too. public void onCreate ( Bundle b ){ /*********/ Button btn = ( Button ) findViewById ( R . id . btn ); btn . setOnClickListener ( new View . OnClickListener () { @Override public void onClick ( View v ) { showPickerDialog (); } }); } private void showPickerDialog () { DatePickerDialog dtPickerDlg = new DatePickerDialog ( this , this , 2017 , 10 , 20 ); dtPickerDialog . show (); } In our xml file, let us have a button and in the onclick listener of the button, let us display the date picker dialog - we call showPickerDialog. In showPickerDialog,  we are using a random date to initialize....