I want to create a spinner for selecting a country and getting its country code.
I already found this item list:
I have a cleaner solution for you. You can use Country Code Picker (CCP) library directly.It will save you from boilerplate code. You just need to place the CountryCodePicker view in your layout XML. This is CCP view
.
Your view will look like with your phone editText.

Download Sample application from PlayStore.
Clicking on CCP will open a dialog with a list of country to select from. Here you can search country with country name, code name, phone code. It also gives an option to autoformat phone number.
Selected country details can be read easily. For more details go to Library's Github page.