I know there is a way to obtain the country name from a country code, but is it also possible the other way arround? I have found so far no function that converts a String like "Netherlands" into "NL". If possible, how can I obtain the country codes?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Not very efficient, but you can try this:
Now, there are a few caveats:
Locale
Or a Kotlin one liner:
As noted in the comments, if you're using Java, depending on how often you call this method, you might want to pull the map out of it but better yet look at the optimised version by @Dambo without the map.
I improved Vlad answer. Because initialize
HashMap
every time you access the method is very bad practice. Unless you initializing the map once. The edited answer:I tried this code, and it works for me.
and for
CountryCodes
you have to put following string in string xmlcreate a jsonObject with country name and value with country codes. e.g.
JSONObject json=new JSONObject(); json.putString('COuntry Name','Country COde');
and save this in prefrences
and to get the same use
json.getString('Country Name')