在更新后使用这些给定值的日,年和月。 我希望他们使用更新的值,请帮忙。
var day = 1
var month = 1
var year = 1999
val dpd = DatePickerDialog(this,android.R.style.Theme_Holo_Dialog,
DatePickerDialog.OnDateSetListener { datePicker, selyear,
monthOfYear, dayOfMonth ->
day = dayOfMonth
month = monthOfYear
year = selyear
tv.text = "$day - $month - $year" /*printing day month year*/
}, year, month, day
)
dpd.show()
val pday = 30 - day /* day = 1(Not the chosen value)*/
val pmonth = 12 - month
val pyear = 2019 - year
答案 0 :(得分:0)
将变量声明从val
更改为var
并在侦听器中更新它们:
val c = Calendar.getInstance()
var day = c.get(Calendar.DAY_OF_MONTH)
var month = c.get(Calendar.MONTH)
var year = c.get(Calendar.YEAR)
val dpd = DatePickerDialog(
this,
android.R.style.Theme_Holo_Dialog,
DatePickerDialog.OnDateSetListener { datePicker, selyear, monthOfYear, dayOfMonth ->
day = dayOfMonth
month = monthOfYear + 1
year = selyear
tv.text = "$day - $month - $year"
}, year, month, day
)
dpd.show()