Last active
March 2, 2022 03:25
-
-
Save heitorpaceli/42aa5a443e2b2cf4fa55585537a5e4c6 to your computer and use it in GitHub Desktop.
initLocalePicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun initLocalePicker() { | |
val systemLocale = getString(R.string.system_locale) | |
val spinner: Spinner = findViewById(R.id.localePicker) | |
val locales = listOf(systemLocale, "en-US", "es-ES", "iw-IL", "ja-JP", "uk-UA") | |
spinner.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, locales) | |
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { | |
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { | |
val selectedLocale = spinner.adapter.getItem(position) as String | |
if (selectedLocale != systemLocale) { | |
updateAppLocales(Locale.forLanguageTag(selectedLocale)) | |
} else { | |
updateAppLocales() | |
} | |
} | |
override fun onNothingSelected(parent: AdapterView<*>?) {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment