LoginSignup
1
2

More than 5 years have passed since last update.

DatePickerDialogメモ①

Posted at

日付情報の初期設定

    Calendar calendar = Calendar.getInstance();
    int year = calendar.get(Calendar.YEAR); // 年
    int monthOfYear = calendar.get(Calendar.MONTH); // 月
    int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); // 日

    Log.d("aaa",String.valueOf(d));

ok押した時の処理

    DatePickerDialog.OnDateSetListener DateSetListener = new DatePickerDialog.OnDateSetListener() {
        //okボタンを押したときの年月日を取得できる
        public void onDateSet(android.widget.DatePicker datePicker, int year,
                              int monthOfYear, int dayOfMonth) {

            //押されてる日時を変数へ
            y=year;
            m=monthOfYear;
            d=dayOfMonth;

        }
    };

表示

    // 日付設定ダイアログの作成・リスナの登録
    datePickerDialog = new DatePickerDialog(this, DateSetListener, y, m, d);

    // 日付設定ダイアログの表示
    datePickerDialog.show();
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2