1

i am developing an android applicATION... in which there is a datepicker for date of birth to be selected... But when the date is displayed... for example date is january 0 is displayed instead of 1 and for february 1 is displayed instead of 2.. and I need to value of date in 3 textviews... for example if date is 04/02/1984 ... i need to take 04 to one textview and 2 to another and 1984 to another one.... pls help..

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


     final DatePicker date = (DatePicker) findViewById(R.id.datePicker1);
     final TextView tvDate = (TextView) findViewById(R.id.textView2);


     date.init(date.getYear(), date.getMonth(), date.getDayOfMonth(),new OnDateChangedListener()
     {


    @Override
    public void onDateChanged(DatePicker  arg0,int arg1, int arg2, int arg3) {
        // TODO Auto-generated method stub



         String date=Integer.toString(arg1);
         String month=Integer.toString(arg2);
         String year=Integer.toString(arg3);

         tvDate.setText(date + month + year);

    }



}
    );

    }
}
roshanpeter
  • 1,334
  • 3
  • 13
  • 32
  • why do you need 3 textviews can't you use one and display the date? check this if it helps http://stackoverflow.com/questions/18211684/how-to-transfer-the-formatted-date-string-from-my-datepickerfragment/18212061#18212061 – Raghunandan Aug 28 '13 at 11:20

2 Answers2

0

You have to create three TextView and set date, month and year individually.

Vimal Bera
  • 10,346
  • 4
  • 25
  • 47
0

You could do followings:

Calendar cal = Calendar.getInstance();
cal.set(Calendar.DATE, arg3);
cal.set(Calendar.MONTH, arg2);
cal.set(Calendar.YEAR, arg1);

DateFormat dayFormat = new SimpleDateFormat("dd");
DateFormat monthFormat = new SimpleDateFormat("MM");
DateFormat yearFormat = new SimpleDateFormat("yyyy");

String date = dayFormat.format(cal.getTime());
String month = monthFormat.format(cal.getTime());
String year = yearFormat.format(cal.getTime());
Shamim Ahmmed
  • 8,265
  • 6
  • 25
  • 36