0

I need to show the date of birth value in a date picker dialog. The purpose is, the user can able to update his data of birth value. Here my problem is when i click the textview it shows the date picker dialog but it show wrong month ie if i text view values is 2/2/1980 (mm/dd/yy) means its show 3/2/1980.I used the following code show and update the date of birth,

text_DOB.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                DialogFragment newFragment = new SelectDateFragment();
                newFragment.show(getActivity().getFragmentManager(),
                        "DatePicker");
            }
        });



    public class SelectDateFragment extends DialogFragment implements
            DatePickerDialog.OnDateSetListener {
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            String[] dateSpliting = text_DOB.getText().toString().trim()
                    .split("/");
          // Here i return the date, month and year values which is in the textview

            return new DatePickerDialog(getActivity(), SelectDateFragment.this,
                    Integer.parseInt(dateSpliting[2]),
                    Integer.parseInt(dateSpliting[1]),
                    Integer.parseInt(dateSpliting[0]));
        }

        public void onDateSet(DatePicker view, int yy, int mm, int dd) {

            text_DOB.setText(new StringBuilder().append(mm + 1).append("/")
                    .append(dd).append("/").append(yy).append(" "));
            view.updateDate(yy, mm + 1, dd);
        }
    }

I can't find out the issue, how can i show the textview date in date picker.

Aerrow
  • 12,086
  • 10
  • 56
  • 90
  • check this if it helps http://stackoverflow.com/questions/18211684/how-to-transfer-the-formatted-date-string-from-my-datepickerfragment/18212061#18212061 – Raghunandan Aug 14 '13 at 17:13
  • @Raghunandan: There is no problem to showing the current date, in my case the date value is already shown in text view i need to show it then the user may or may not update. – Aerrow Aug 14 '13 at 17:36
  • ok. i might have misunderstood the problem – Raghunandan Aug 14 '13 at 17:40

1 Answers1

0

You are adding 1 to the month. And you are saying that it's printing a month more. So that is probably the problem.

view.updateDate(yy, mm + 1, dd);


view.updateDate(yy, mm, dd);
andr3ina
  • 19
  • 4
  • what if you move this line view.updateDate(yy, mm + 1, dd); over this text_DOB.setText(new StringBuilder().append(mm + 1).append("/") .append(dd).append("/").append(yy).append(" ")); – andr3ina Aug 15 '13 at 18:49