2013-08-28 3 views
1

나는 안드로이드 응용 프로그램을 개발 중입니다 ... 선택되는 생년월일의 날짜 피커가 있습니다 ... 그러나 날짜가 표시 될 때 ... 예를 들어 날짜가 1 월 0 일인 경우 1 대신 표시되고 2 월 1 일 2 대신 표시됩니다 .. 그리고 3 textviews 날짜의 가치가 필요합니다 ... 예를 들어 날짜가 04/02/1984 경우 ... 나는 한 textview에 04 걸릴 필요가 및 2 다른 또 다른 1984 년에 .... PLS ..텍스트 뷰에 날짜 표시 값 표시

@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); 

    } 



} 
    ); 

    } 
} 
+0

가 왜 3 textviews 당신이 하나를 사용하여 날짜를 표시 할 수 없습니다 필요합니까? 도움이되는지 확인하십시오. http://stackoverflow.com/questions/18211684/how-to-transfer-the-formatted-date-string-from-my-datepickerfragment/18212061#18212061 – Raghunandan

답변

0

당신은 세 개의 텍스트 뷰와 설정 날짜, 개별적 월 및 연도를 만들 필요가 도움이됩니다.

0

당신은 다음을 할 수있는 :

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()); 
관련 문제