2016-10-12 10 views
-1

現在の日付を設定したいが、現在の日付の前と現在の日付の前に日付を選択する。DatePickerで現在の日付を設定する

c = Calendar.getInstance(); 
year = c.get(Calendar.YEAR); 
month = c.get(Calendar.MONTH); 
day = c.get(Calendar.DAY_OF_MONTH); 

datePicker = new DatePickerDialog(view.getContext(), new DatePickerDialog.OnDateSetListener() { 
    @Override 
    public void onDateSet(DatePicker view, int year, int month, int day) { 
     daynum = (TextView) getActivity().findViewById(R.id.daynum); 
     daynum.setText(view.getDayOfMonth()+ "-" + (view.getMonth()+1)+ "-" + view.getYear()); 
     new ReadJSON().execute("url"+"day=" + view.getDayOfMonth() + "&" + "month=" + (view.getMonth()+1) + "&" + "year=" + view.getYear()); 
     new ReadJSON1().execute("url" + "day=" + view.getDayOfMonth() + "&" + "month=" + (view.getMonth()+1) + "&" + "year=" + view.getYear()); 
    } 
}, day, month, year); 
datePicker.getDatePicker().setMinDate(c.getTimeInMillis()); 
datePicker.setTitle("Select Date"); 
datePicker.show(); 
+0

あなたの質問を編集することができます。誰かに返信しない限り、コメントする必要はありません –

答えて

0

私はちょうど私が欲しいものを見つけました。返信いただきありがとうございます。

c = Calendar.getInstance(); 
    year = c.get(Calendar.YEAR); 
    month = c.get(Calendar.MONTH); 
    day = c.get(Calendar.DAY_OF_MONTH); 

    datePicker = new DatePickerDialog(view.getContext(), new DatePickerDialog.OnDateSetListener() { 
     @Override 
     public void onDateSet(DatePicker view, int year, int month, int day) { 
      daynum = (TextView) getActivity().findViewById(R.id.daynum); 
      daynum.setText(view.getDayOfMonth()+ "-" + (view.getMonth()+1)+ "-" + view.getYear()); 
      new ReadJSON().execute("url"+"day=" + view.getDayOfMonth() + "&" + "month=" + (view.getMonth()+1) + "&" + "year=" + view.getYear()); 
      new ReadJSON1().execute("url" + "day=" + view.getDayOfMonth() + "&" + "month=" + (view.getMonth()+1) + "&" + "year=" + view.getYear()); 
     } 
    }, day, month, year); 
    //subtract -3000 to select date before current date 
     c.add(Calendar.DATE, -3000); 
    datePicker.getDatePicker().setMinDate(c.getTimeInMillis()); 
    datePicker.setTitle("Select Date"); 
    datePicker.show(); 
0

これは非常に簡単です。

Calendar c = Calendar.getInstance(); 
year = c.get(Calendar.YEAR); 
month = c.get(Calendar.MONTH); 
day = c.get(Calendar.DAY_OF_MONTH); 

//set selected date into datepicker also 
dpResult.init(year, month, day, null); 

それとも

DatePickerDialog dialog = new DatePickerDialog(this, datePickerListener, year, month, day); 

private DatePickerDialog.OnDateSetListener datePickerListener 
       = new DatePickerDialog.OnDateSetListener() { 

     // when dialog box is closed, below method will be called. 
     public void onDateSet(DatePicker view, int selectedYear, 
       int selectedMonth, int selectedDay) 
     { 

     } 
}; 

complete tutorialを参照してください。

+0

お返事ありがとうございます – Nico

関連する問題