0

In my android application. I have an registration page, where user have to enter his/her mobile no.

I want to display an spinner on left side of mobile no textview. when click on spinner is show a list of (country name, country calling code(ISD no). after selection on particular row country code should be reflect in mobile no. textview and after that Mobile No should be entered.

As there in Gmail Registration Page.

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
  • check this link,http://stackoverflow.com/questions/23291199/how-to-get-country-isd-code-when-user-select-country-name-from-spinner – Jignesh Jain Apr 06 '15 at 10:55
  • thanks Jignesh. But i am searching some java classes of any inbuilt function or any 3rd party to get country name and isd codes with flags, as there DatePickerDialog in Java. – Arvind kanojiya Apr 06 '15 at 10:59
  • possible duplicate of [Getting telephone country code with Android](http://stackoverflow.com/questions/5402253/getting-telephone-country-code-with-android) – Veaceslav Gaidarji Apr 06 '15 at 12:03

2 Answers2

1

Just use some simple dropdown Spinner with listview and pass a string array which contains all country names and country calling (ISD). Something like this:

<string-array name="CountryCodes" >
<item>93,AF</item>
<item>355,AL</item>
<item>297,AW</item>
<item>61,AU</item>
<item>43,AT</item>
<item>994,AZ</item>
<item>973,BH</item>
<item>880,BD</item>
<item>375,BY</item>
<item>32,BE</item>
<item>501,BZ</item>
<item>229,BJ</item>
<item>975,BT</item>
<item>591,BO</item>
<item>387,BA</item>
<item>267,BW</item>
<item>55,BR</item>
<item>673,BN</item>
<item>359,BG</item>
<item>226,BF</item>
<item>95,MM</item>
<item>257,BI</item>
<item>855,KH</item>
<item>237,CM</item>
<item>1,CA</item>
<item>238,CV</item>
<item>236,CF</item>
<item>235,TD</item>
<item>56,CL</item>
<item>86,CN</item>
<item>61,CX</item>
<item>61,CC</item>
<item>57,CO</item>
<item>269,KM</item>
<item>242,CG</item>
<item>243,CD</item>
<item>682,CK</item>
<item>506,CR</item>
<item>385,HR</item>
<item>53,CU</item>
<item>357,CY</item>
<item>420,CZ</item>
<item>45,DK</item>
<item>263,ZW</item>
</string-array>

Here is the complete list. And Here are some tutorial (this or this) for spinners with listview. and when user will select one from the list then do something like this:

public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// Get select item
int sid=spinnerDropDown.getSelectedItemPosition();
your_txtview.setText(""+ countries[sid]);
 }

Here you go! Cheers!!

Community
  • 1
  • 1
Fahid Nadeem
  • 412
  • 2
  • 7
  • 19
1

Please refer below code it may help you

    private ArrayList<String> mCountries = new ArrayList<String>();
    public void getCountryData()
    {
        Locale[] locales = Locale.getAvailableLocales();
         for (Locale locale : locales)
         {
                String country = locale.getDisplayCountry();
                if (country.trim().length()>0 && !mCountries.contains(country))
                {
                    mCountries.add(country);
                }
          }
            Collections.sort(mCountries);
    }
  • hey. Thanks for your code. Its working as i expected. but here i only getting Country Name in Spinner. And what i wanted is to display country calling codes (ISD Codes) in TextView when user select particular country from spinner. (Eg. India ----> it should display +91) – Arvind kanojiya Apr 08 '15 at 08:00