'how do i get the days of the week using kotlin in android studio?

I'm trying to get the day number to put that number in a textView. for example, we know that today is Wednesday the 26th, knowing this information, I want to take this number "26" and put it inside a textView that will be displayed inside a screen that has a weekly calendar. so I try to help create a logic that tells me if it's Wednesday it returns the current day of the week (26), if I tell Thursday, it returns me (27) and so on for the entire week. tks. ;)

val diaDaSemana: DayOfWeek
    diaDaSemana.get(DayOfWeek.THURSDAY)
    binding.txtNumeroQuarta = diaDaSemana.toString()

I'm trying this way to get the day.

calender image :

calender image

basically I just want the number informing the week, for example, I inform you that it's Wednesday, then you have to return me on the 26th so I can put it in the textView.



Solution 1:[1]

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.

Solution 2:[2]

val day = Calendar.DAY_OF_MONTH.toString()
binding.txtNumeroTerca.text = day

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Karol
Solution 2