Wednesday, 27 November 2019

datePicker in android

I want date picker in which i can select year, month and date. like this,

enter image description here

But i get date picker like this,

enter image description here

I want to select year and month but in above date picker i can select only month This is my code :

DatePickerDialog.OnDateSetListener mDateListener;

edBirthday.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Calendar cal = Calendar.getInstance();
                int year = cal.get(Calendar.YEAR);
                int month = cal.get(Calendar.MONTH);
                int day = cal.get(Calendar.DAY_OF_MONTH);

                DatePickerDialog dialog =  new DatePickerDialog(
                        RegisterActivity.this,
                        android.R.style.Theme_Holo_Light_Dialog_MinWidth,
                        mDateListener,
                        year,month,day
                );
                dialog.getWindow().setBackgroundDrawable( new ColorDrawable( Color.TRANSPARENT ) );
                dialog.show();
            }
        } );

        mDateListener = new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker datePicker ,int year ,int month ,int day) {
                month = month + 1;

                Log.d( "onDateSet" , month + "/" + day + "/" + year );
                edBirthday.setText( new StringBuilder().append( day ).append( "-" )
                        .append( month ).append( "-" ).append( year ) );
            }
        };


from datePicker in android

No comments:

Post a Comment