What if Let's say, I want to get the target language from a spinner or something like that
abedyngash opened this issue · 1 comments
abedyngash commented
What if Let's say, I want to get the target language from a spinner or something like that
abdnezar commented
1- implement AdapterView.OnItemSelectedListener
var language = "'
2- override this:
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
Log.e(TAG, "Selected Language ID : ${parent?.getItemIdAtPosition(position)}")
when(parent?.getItemIdAtPosition(position)?.toInt()) {
0 -> language = "eng"
1 -> language = "bul"
2 -> language = "chs"
3 -> language = "cht"
4 -> language = "hrv"
5 -> language = "cze"
6 -> language = "dan"
7 -> language = "dut"
8 -> language = "ara"
9 -> language = "fin"
10 -> language = "fre"
11 -> language = "ger"
12 -> language = "gre"
13 -> language = "hun"
14 -> language = "kor"
15 -> language = "ita"
16 -> language = "jpn"
17 -> language = "pol"
18 -> language = "por"
19 -> language = "rus"
20 -> language = "slv"
21 -> language = "spa"
22 -> language = "swe"
23 -> language = "tur"
24 -> language = ""
}
}
override fun onNothingSelected(parent: AdapterView<*>?) {
TODO("Not yet implemented")
}
3- xml :
<Spinner
android:id="@+id/spLng"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.7"
android:drawSelectorOnTop="true"
android:entries="@array/languages_array"/>
4- in res/string :
<item>English (Default)</item>
<item>Bulgarian</item>
<item>Chinese(Simplified)</item>
<item>Chinese(Traditional)</item>
<item>Croatian</item>
<item>Czech</item>
<item>Danish</item>
<item>Dutch</item>
<item>Arabic</item>
<item>Finnish</item>
<item>French</item>
<item>German</item>
<item>Greek</item>
<item>Hungarian</item>
<item>Korean</item>
<item>Italian</item>
<item>Japanese</item>
<item>Polish</item>
<item>Portuguese</item>
<item>Russian</item>
<item>Slovenian</item>
<item>Spanish</item>
<item>Swedish</item>
<item>Turkish</item>
<item>Other Languages (with Latin Character)</item>
</string-array>