Skip to content

Instantly share code, notes, and snippets.

@heitorpaceli
Last active March 2, 2022 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heitorpaceli/42aa5a443e2b2cf4fa55585537a5e4c6 to your computer and use it in GitHub Desktop.
Save heitorpaceli/42aa5a443e2b2cf4fa55585537a5e4c6 to your computer and use it in GitHub Desktop.
initLocalePicker
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