Custom DatePicker in Android?

后端 未结 4 775
臣服心动
臣服心动 2020-12-14 13:04

How to make the datepicker in spin view. Here is the image, \"enter

I want the datepi

4条回答
  •  醉梦人生
    2020-12-14 13:33

    @Override
    parentView.findViewById(R.id.changeDate).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
             DialogFragment newFragment = new SelectDateFragmentTrans();
             newFragment.show(getFragmentManager(), "DatePicker");       
        }
    });
    

    SelectDateFragmentTrans.java:

    public class SelectDateFragmentTrans extends DialogFragment
            implements DatePickerDialog.OnDateSetListener {
    
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            final Calendar calendar = Calendar.getInstance();
            int yy = calendar.get(Calendar.YEAR);
            int mm = calendar.get(Calendar.MONTH);
            int dd = calendar.get(Calendar.DAY_OF_MONTH);
            return new DatePickerDialog(getActivity(), this, yy, mm, dd);
        }
    
        public void onDateSet(DatePicker view, int yy, int mm, int dd) {
            populateSetDate(yy, mm+1, dd);
        }
    
        public void populateSetDate(int year, int month, int day) {
            SettingsFragment.date1 = month+"/"+day+"/"+year;
            TransferFragment.date.setText(month+"/"+day+"/"+year);
        }
    }
    

提交回复
热议问题