I'm trying to get the days of the week to put in a weekly calendar on a screen. Basically it's getting the numbers of the days of the week and putting it in a textView, for example, today is the 25th, then taking this '25' and putting it in a textView and so on every day of the week, but I'm unsuccessful. I'm trying like this:
val calendar: Calendar = Calendar.getInstance()
val day = calendar.add(Calendar.DAY_OF_MONTH, Calendar.TUESDAY)
binding.txtNumeroTerca.text = day.toString()
[enter image description here][1]
when I run the app it looks like this, someone help please? [1]: https://i.stack.imgur.com/jw89K.jpg
CodePudding user response:
val day = Calendar.DAY_OF_WEEK.toString()
binding.txtNumeroTerca.text = day
CodePudding user response:
It is because add() method returns nothing. If you want to get day of month, try something like that:
val calendar: Calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_MONTH, Calendar.TUESDAY)
val day= calendar.get(Calendar.DAY_OF_MONTH)
binding.txtNumeroTerca.text = day.toString()
And I recommend using numbers in add() method than code of week days.
