private fun bindExpiryMonthDropDown(expiryMonth: Int) { val adapter = ArrayAdapter<String>( binding.root.context, android.R.layout.simple_spinner_dropdown_item, ) val dateFormat = SimpleDateFormat("MMMM (MM)", Locale.getDefault()) val calendar = Calendar.getInstance() calendar.set(Calendar.DAY_OF_MONTH, 1) for (month in 0..NUMBER_OF_MONTHS) { calendar.set(Calendar.MONTH, month) adapter.add(dateFormat.format(calendar.time)) } binding.expiryMonthDropDown.adapter = adapter binding.expiryMonthDropDown.setSelection(expiryMonth - 1) }
Setup the expiry month dropdown by formatting and populating it with the months in a calendar year, and set the selection to the provided expiry month.