본문 바로가기
경험들/토이 프로젝트

"할일관리 어플" #3 datepickerDialog

by 시아나 2022. 4. 6.


//Activity.kt

        binding.editMainDateBtn.setOnClickListener{
            val cal = Calendar.getInstance()
            DatePickerDialog(this@EditMainPlanActivity,{datePicker, year, month, date -> //datepickerdialog 띄우기
                binding.editMainDateBtn.text = "${String.format("%04d",year)}.${String.format("%02d",month+1)}.${String.format("%02d",date)}" //버튼 text 변경
                binding.editMainDDayTxt.text = MyCalendar.getInstance().getDday(year,month,date) //d-day 설정
                Toast.makeText(this@EditMainPlanActivity,"$year.${month+1}.$date",Toast.LENGTH_SHORT).show()
            }, cal.get(Calendar.YEAR),cal.get(Calendar.MARCH),cal.get(Calendar.DATE)).show()
        }

 

<!-- xml -->
            <Button
                android:id="@+id/editMain_dateBtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/btn_date"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/main_item_dDay"
                android:textSize="@dimen/txt_mideum"
                app:layout_constraintBottom_toTopOf="@+id/guideline5"
                app:layout_constraintEnd_toStartOf="@+id/guideline4"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/editMain_dDayTxt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/main_item_date"
                android:textSize="@dimen/txt_mideum"
                app:layout_constraintBottom_toTopOf="@+id/guideline5"
                app:layout_constraintEnd_toStartOf="@+id/guideline6"
                app:layout_constraintStart_toStartOf="@+id/guideline4"
                app:layout_constraintTop_toTopOf="parent" />

'경험들 > 토이 프로젝트' 카테고리의 다른 글

"할일관리 어플" #2 recyclerview  (0) 2022.03.29
"할일관리 어플" #1 달력 만들기  (0) 2022.03.29