Search code examples
androidandroid-studiokotlinandroid-calendar

How to change photo according to current month?


I want to build a Photo Calendar app. As a beginner my question is - I draw 12 picture using Photoshop for 12 months, and placed in my app . But I need to know how to make them arranged so ,

when some one opened the app If current month is January then 1st picture seen in home If current month is February then 2nd picture seen in home And so on

Thank You


Solution

  • val calendar = Calendar.getInstance()
    
    when (calendar[Calendar.MONTH]) {
      1 -> //set first month picture
      2 -> //same
      ...
    }
    

    Get a calendar instance using getInstance(), this will return a calendar object initialized with current device time/date. You should get an instance in onCreate() of your activity/fragment and from there you check the current month and apply the image accordingly.