web-dev-qa-db-ja.com

Android OSから国のリストを取得する

スピナーに国のリストと名前を入力する方法を探しています。 Android OSから取得できますか?例を教えてください。

30
roses_r

Locale クラスからアイデアを得ることができます。

getAvailableLocales() を呼び出してから、配列を繰り返し処理します- getDisplayCountry() 。その国名を初めて見た場合は、それを展開可能なリストに追加します(例:ArrayListインスタンス)。


例えば。

Javaでは、Java.utilの3つのクラスはすべてAndroidで使用可能です。

import Java.util.*;

class Countries {

    public static void main(String[] args) {
        Locale[] locales = Locale.getAvailableLocales();
        ArrayList<String> countries = new ArrayList<String>();
        for (Locale locale : locales) {
            String country = locale.getDisplayCountry();
            if (country.trim().length()>0 && !countries.contains(country)) {
                countries.add(country);
            }
        }
        Collections.sort(countries);
        for (String country : countries) {
            System.out.println(country);
        }
        System.out.println( "# countries found: " + countries.size());
    }
}

このデスクトップPCでの出力

Albania
Algeria
Argentina
Australia
..
Venezuela
Vietnam
Yemen
# countries found: 95
Press any key to continue . . .
46
Andrew Thompson

Locale.getISOCountries() を使用して、2文字の国コードすべてのリストを取得できます。 2文字の国コードからLocaleオブジェクトを構築し、 Locale.getDisplayName() を使用して国名を取得できます。

String[] isoCountryCodes = Locale.getISOCountries();
for (String countryCode : isoCountryCodes) {
    Locale locale = new Locale("", countryCode);
    String countryName = locale.getDisplayCountry();
}

Galaxy Note 3でAndroid 4.3を実行すると、getISOCountries()は246の国コードを返します。これは、今日(11/24/14)の公式に割り当てられた249のISO国コードにかなり近いです。

GetAvailableLocales()を呼び出すと、デバイスにインストールされているロケールのみが返されます。このロケールには、ほとんどの国がありません。

30
Ilan Klinghofer

私はこのためのクラスを作成しました、それが助けになるかもしれません。

public class CountryDetails {

public static String[] country = new String[]{"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla",

        "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria",

        "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium",

        "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana",

        "Brazil", "British Indian Ocean Territory", "British Virgin Islands", "Brunei", "Bulgaria",

        "Burkina Faso", "Burma (Myanmar)", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde",

        "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island",

        "Cocos (Keeling) Islands", "Colombia", "Comoros", "Cook Islands", "Costa Rica",

        "Croatia", "Cuba", "Cyprus", "Czech Republic", "Democratic Republic of the Congo",

        "Denmark", "Djibouti", "Dominica", "Dominican Republic",

        "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia",

        "Ethiopia", "Falkland Islands", "Faroe Islands", "Fiji", "Finland", "France", "French Polynesia",

        "Gabon", "Gambia", "Gaza Strip", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece",

        "Greenland", "Grenada", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana",

        "Haiti", "Holy See (Vatican City)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India",

        "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Ivory Coast", "Jamaica",

        "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kosovo", "Kuwait",

        "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein",

        "Lithuania", "Luxembourg", "Macau", "Macedonia", "Madagascar", "Malawi", "Malaysia",

        "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mayotte", "Mexico",

        "Micronesia", "Moldova", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco",

        "Mozambique", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia",

        "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea",

        "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama",

        "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn Islands", "Poland",

        "Portugal", "Puerto Rico", "Qatar", "Republic of the Congo", "Romania", "Russia", "Rwanda",

        "Saint Barthelemy", "Saint Helena", "Saint Kitts and Nevis", "Saint Lucia", "Saint Martin",

        "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino",

        "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone",

        "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Korea",

        "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", "Switzerland",

        "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tokelau",

        "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands",

        "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "US Virgin Islands", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam",

        "Wallis and Futuna", "West Bank", "Yemen", "Zambia", "Zimbabwe"};

public static String[]  code = new String[]{"+93", "+355", "+213", "+1 684", "+376", "+244", "+1 264", "+672", "+1 268", "+54", "+374",

        "+297", "+61", "+43", "+994", "+1 242", "+973", "+880", "+1 246", "+375", "+32", "+501",

        "+229", "+1 441", "+975", "+591", "+387", "+267", "+55", "+246", "+1 284", "+673", "+359",

        "+226", "+95", "+257", "+855", "+237", "+1", "+238", "+1 345", "+236", "+235", "+56", "+86",

        "+61", "+891", "+57", "+269", "+682", "+506", "+385", "+53", "+357", "+420", "+243", "+45",

        "+253", "+1 767", "+1 849", "+1 829", "+1 809", "+593", "+20", "+503", "+240", "+291", "+372",

        "+251", "+500", "+298", "+679", "+358", "+33", "+689", "+241", "+220", "+970", "+995", "+49",

        "+233", "+350", "+30", "+299", "+1 473", "+1 671", "+502", "+224", "+245", "+592", "+509",

        "+379", "+504", "+852", "+36", "+354", "+91", "+62", "+98", "+964", "+353", "+44", "+972",

        "+39", "+225", "+1 876", "+81", "+44", "+962", "+7", "+254", "+686", "+381", "+965", "+996",

        "+856", "+371", "+961", "+266", "+231", "+218", "+423", "+370", "+352", "+853", "+389",

        "+261", "+265", "+60", "+960", "+223", "+356", "+692", "+222", "+230", "+262", "+52", "+691",

        "+373", "+377", "+976", "+382", "+1 664", "+212", "+258", "+264", "+674", "+977", "+31",

        "+599", "+687", "+64", "+505", "+227", "+234", "+683", "+672", "+850", "+1 670", "+47",

        "+968", "+92", "+680", "+507", "+675", "+595", "+51", "+63", "+870", "+48", "+351", "+1",

        "+974", "+242", "+40", "+7", "+250", "+590", "+290", "+1 869", "+1 758", "+1 599", "+508",

        "+1 784", "+685", "+378", "+239", "+966", "+221", "+381", "+248", "+232", "+65", "+421",

        "+386", "+677", "+252", "+27", "+82", "+34", "+94", "+249", "+597", "+268", "+46", "+41",

        "+963", "+886", "+992", "+255", "+66", "+670", "+228", "+690", "+676", "+1 868", "+216",

        "+90", "+993", "+1 649", "+688", "+256", "+380", "+971", "+44", "+1", "+598", "+1 340",

        "+998", "+678", "+58", "+84", "+681", "+970", "+967", "+260", "+263"};

public String[] getCountry() {
    return country;
}

public String[] getCode() {
    return code;
}
}
13
Ameen Maheen

ジオネームWebサービスを使用します。

  1. 国のリストを取得するには

http://api.geonames.org/countryInfoJSON?username=demo

注:ユーザー名->デモをyour_usernameに変更します

  1. 国に従って州のリストを取得するには(最初のWebサービス結果のgeonameIdを使用)

エクサ。国がインドの場合、geonameId = 1269750

http://api.geonames.org/childrenJSON?geonameId=1269750&username=demo

  1. 状態に応じて都市のリストを取得するには(2番目のWebサービス結果のgeonameIdを使用)

エクサ。マハラシュトラ州の場合、geonameId = 1264418

http://api.geonames.org/childrenJSON?geonameId=1264418&username=demo

12
pathe.kiran

すべての国を表示し、ユーザーが国を選択できるようにするライブラリ( https://github.com/roomorama/AndroidCountryPicker )を作成しました。独自のアクティビティに埋め込むか、ダイアログとして表示できます。

10
thomasdao

以下は、xmlの国名の文字列配列です。

<string-array name="countries" formatted="false" translatable="false">
    <item>Afghanistan</item>
    <item>Albania</item>
    <item>Algeria</item>
    <item>American Samoa</item>
    <item>Andorra</item>
    <item>Angola</item>
    <item>Antigua and Barbuda</item>
    <item>Argentina</item>
    <item>Armenia</item>
    <item>Aruba</item>
    <item>Australia</item>
    <item>Austria</item>
    <item>Azerbaijan</item>
    <item>Bahamas</item>
    <item>Bahrain</item>
    <item>Bangladesh</item>
    <item>Barbados</item>
    <item>Belarus</item>
    <item>Belgium</item>
    <item>Belize</item>
    <item>Benin</item>
    <item>Bermuda</item>
    <item>Bhutan</item>
    <item>Bolivia</item>
    <item>Bosnia and Herzegovina</item>
    <item>Botswana</item>
    <item>Brazil</item>
    <item>British Virgin Islands</item>
    <item>Brunei</item>
    <item>Bulgaria</item>
    <item>Burkina Faso</item>
    <item>Burundi</item>
    <item>Cambodia</item>
    <item>Cameroon</item>
    <item>Canada</item>
    <item>Canary Islands</item>
    <item>Cape Verde</item>
    <item>Cayman Islands</item>
    <item>Central African Republic</item>
    <item>Ceuta and Melilla</item>
    <item>Chad</item>
    <item>Chile</item>
    <item>China</item>
    <item>Colombia</item>
    <item>Comoros</item>
    <item>Congo [DRC]</item>
    <item>Congo [Republic]</item>
    <item>Costa Rica</item>
    <item>Croatia</item>
    <item>Cuba</item>
    <item>Curaçao</item>
    <item>Cyprus</item>
    <item>Czech Republic</item>
    <item>Côte d’Ivoire</item>
    <item>Denmark</item>
    <item>Djibouti</item>
    <item>Dominica</item>
    <item>Dominican Republic</item>
    <item>Ecuador</item>
    <item>Egypt</item>
    <item>El Salvador</item>
    <item>Equatorial Guinea</item>
    <item>Eritrea</item>
    <item>Estonia</item>
    <item>Ethiopia</item>
    <item>Europe</item>
    <item>Faroe Islands</item>
    <item>Fiji</item>
    <item>Finland</item>
    <item>France</item>
    <item>French Guiana</item>
    <item>French Polynesia</item>
    <item>Gabon</item>
    <item>Gambia</item>
    <item>Georgia</item>
    <item>Germany</item>
    <item>Ghana</item>
    <item>Gibraltar</item>
    <item>Greece</item>
    <item>Greenland</item>
    <item>Grenada</item>
    <item>Guadeloupe</item>
    <item>Guam</item>
    <item>Guatemala</item>
    <item>Guernsey</item>
    <item>Guinea</item>
    <item>Guinea-Bissau</item>
    <item>Guyana</item>
    <item>Haiti</item>
    <item>Honduras</item>
    <item>Hong Kong</item>
    <item>Hungary</item>
    <item>Iceland</item>
    <item>India</item>
    <item>Indonesia</item>
    <item>Iran</item>
    <item>Iraq</item>
    <item>Ireland</item>
    <item>Isle of Man</item>
    <item>Israel</item>
    <item>Italy</item>
    <item>Jamaica</item>
    <item>Japan</item>
    <item>Jersey</item>
    <item>Jordan</item>
    <item>Kazakhstan</item>
    <item>Kenya</item>
    <item>Kiribati</item>
    <item>Kuwait</item>
    <item>Kyrgyzstan</item>
    <item>Laos</item>
    <item>Latin America</item>
    <item>Latvia</item>
    <item>Lebanon</item>
    <item>Lesotho</item>
    <item>Liberia</item>
    <item>Libya</item>
    <item>Liechtenstein</item>
    <item>Lithuania</item>
    <item>Luxembourg</item>
    <item>Macau</item>
    <item>Macedonia [FYROM]</item>
    <item>Madagascar</item>
    <item>Malawi</item>
    <item>Malaysia</item>
    <item>Mali</item>
    <item>Malta</item>
    <item>Marshall Islands</item>
    <item>Martinique</item>
    <item>Mauritania</item>
    <item>Mauritius</item>
    <item>Mayotte</item>
    <item>Mexico</item>
    <item>Micronesia</item>
    <item>Moldova</item>
    <item>Monaco</item>
    <item>Mongolia</item>
    <item>Montenegro</item>
    <item>Morocco</item>
    <item>Mozambique</item>
    <item>Myanmar [Burma]</item>
    <item>Namibia</item>
    <item>Nepal</item>
    <item>Netherlands</item>
    <item>New Caledonia</item>
    <item>New Zealand</item>
    <item>Nicaragua</item>
    <item>Niger</item>
    <item>Nigeria</item>
    <item>North Korea</item>
    <item>Northern Mariana Islands</item>
    <item>Norway</item>
    <item>Oman</item>
    <item>Pakistan</item>
    <item>Palau</item>
    <item>Palestine</item>
    <item>Panama</item>
    <item>Papua New Guinea</item>
    <item>Paraguay</item>
    <item>Peru</item>
    <item>Philippines</item>
    <item>Poland</item>
    <item>Portugal</item>
    <item>Puerto Rico</item>
    <item>Qatar</item>
    <item>Romania</item>
    <item>Russia</item>
    <item>Rwanda</item>
    <item>Réunion</item>
    <item>Saint Barthélemy</item>
    <item>Saint Kitts and Nevis</item>
    <item>Saint Lucia</item>
    <item>Saint Martin</item>
    <item>Saint Vincent and the Grenadines</item>
    <item>Samoa</item>
    <item>San Marino</item>
    <item>Saudi Arabia</item>
    <item>Senegal</item>
    <item>Serbia</item>
    <item>Seychelles</item>
    <item>Sierra Leone</item>
    <item>Singapore</item>
    <item>Sint Maarten</item>
    <item>Slovakia</item>
    <item>Slovenia</item>
    <item>Solomon Islands</item>
    <item>Somalia</item>
    <item>South Africa</item>
    <item>South Korea</item>
    <item>South Sudan</item>
    <item>Spain</item>
    <item>Sri Lanka</item>
    <item>Sudan</item>
    <item>Suriname</item>
    <item>Swaziland</item>
    <item>Sweden</item>
    <item>Switzerland</item>
    <item>Syria</item>
    <item>São Tomé and Príncipe</item>
    <item>Taiwan</item>
    <item>Tanzania</item>
    <item>Thailand</item>
    <item>Timor-Leste</item>
    <item>Togo</item>
    <item>Tonga</item>
    <item>Trinidad and Tobago</item>
    <item>Tunisia</item>
    <item>Turkey</item>
    <item>Turks and Caicos Islands</item>
    <item>U.S. Outlying Islands</item>
    <item>U.S. Virgin Islands</item>
    <item>Uganda</item>
    <item>Ukraine</item>
    <item>United Arab Emirates</item>
    <item>United Kingdom</item>
    <item>United States</item>
    <item>Uruguay</item>
    <item>Uzbekistan</item>
    <item>Vanuatu</item>
    <item>Venezuela</item>
    <item>Vietnam</item>
    <item>Western Sahara</item>        
    <item>Yemen</item>
    <item>Zambia</item>
    <item>Zimbabwe</item>
    <item>Åland Islands</item>
</string-array>
9
Aditya Naique

ここにソートされたリストを提供するKotlin関数があります

var normalArray     = arrayListOf<Country>()
fun preparedata() {
    for (countryCode in Locale.getISOCountries()) {
        val locale = Locale("",countryCode)
        var countryName: String? = locale.displayCountry
        if (countryName == null) {
            countryName = "UnIdentified"
        }
        val simpleCountry = Country(countryName,countryCode)
        normalArray.add(simpleCountry)
    }
    normalArray = ArrayList(normalArray.sortedWith(compareBy { it.countryName }))
}

国はデータクラスです

data class Country(val countryName:String, val countryCode:String){

}

国リストとその詳細を表示するサンプルプロジェクトを次に示します。

WorldCountries Kotlin

2
anoop4real

@ Ameen Maheen解決策にはいくつかのエラーがあります。国名に従って、正しい国コード ..だから私は国と国コードのリストを修正しました...世界中に24国があります...だから解決策があります:)

CountryDetailsクラス:-

public class CountryDetails {

public static String[] country = new String[]{
        "Afghanistan",
        "Albania",
        "Algeria",
        "American Samoa",
        "Andorra",
        "Angola",
        "Anguilla",
        "Antarctica",
        "Antigua and Barbuda",
        "Argentina",
        "Armenia",
        "Aruba",
        "Australia",
        "Austria",
        "Azerbaijan",
        "Bahamas",
        "Bahrain",
        "Bangladesh",
        "Barbados",
        "Belarus",
        "Belgium",
        "Belize",
        "Benin",
        "Bermuda",
        "Bhutan",
        "Bolivia",
        "Bosnia and Herzegovina",
        "Botswana",
        "Brazil",
        "British Indian Ocean Territory",
        "British Virgin",
        "Brunei",
        "Bulgaria",
        "Burkina Faso",
        "Burundi",
        "Cambodia",
        "Cameroon ",
        "Canada",
        "Cape Verde",
        "Cayman Islands",
        "Central African Republic",
        "Chad",
        "Chile",
        "China",
        "Christmas Island",
        "Cocos Islands",
        "Colombia",
        "Comoros",
        "Cook Islands",
        "Costa Rica",
        "Croatia",
        "Cuba ",
        "Curacao",
        "Cyprus ",
        "Czech Republic",
        "Democratic Republic of the Congo",
        "Denmark ",
        "Djibouti ",
        "Dominica ",
        "Dominican Republic",
        "East Timor",
        "Ecuador",
        "Egypt ",
        "El Salvador",
        "Equatorial Guinea",
        "Eritrea ",
        "Estonia ",
        "Ethiopia ",
        "Falkland Islands ",
        "Faroe Islands ",
        "Fiji ",
        "Finland ",
        "France",
        "French Polynesia",
        "Gabon ",
        "Gambia",
        "Georgia ",
        "Germany ",
        "Ghana ",
        "Gibraltar",
        "Greece ",
        "Greenland",
        "Grenada ",
        "Guam ",
        "Guatemala",
        "Guernsey ",
        "Guinea ",
        "Guinea-Bissau",
        "Guyana",
        "Haiti ",
        "Honduras ",
        "Hong Kong ",
        "Hungary ",
        "Iceland ",
        "India ",
        "Indonesia ",
        "Iran ",
        "Iraq ",
        "Ireland ",
        "Isle of Man ",
        "Israel",
        "Italy ",
        "Ivory Coast",
        "Jamaica ",
        "Japan ",
        "Jersey ",
        "Jordan ",
        "Kazakhstan",
        "Kenya ",
        "Kiribati",
        "Kosovo",
        "Kuwait ",
        "Kyrgyzstan",
        "Laos ",
        "Latvia",
        "Lebanon ",
        "Lesotho ",
        "Liberia ",
        "Libya ",
        "Liechtenstein",
        "Lithuania",
        "Luxembourg",
        "Macau ",
        "Macedonia",
        "Madagascar",
        "Malawi",
        "Malaysia",
        "Maldives ",
        "Mali ",
        "Malta ",
        "Marshall Islands ",
        "Mauritania",
        "Mauritius ",
        "Mayotte ",
        "Mexico ",
        "Micronesia",
        "Moldova ",
        "Monaco ",
        "Mongolia",
        "Montenegro",
        "Montserrat",
        "Morocco ",
        "Mozambique",
        "Myanmar ",
        "Namibia ",
        "Nauru ",
        "Nepal ",
        "Netherlands",
        "Netherlands Antilles",
        "New Caledonia ",
        "New Zealand ",
        "Nicaragua ",
        "Niger ",
        "Nigeria",
        "Niue ",
        "North Korea",
        "Northern Mariana Islands",
        "Norway ",
        "Oman ",
        "Pakistan",
        "Palau ",
        "Palestine",
        "Panama ",
        "Papua New Guinea",
        "Paraguay ",
        "Peru ",
        "Philippines ",
        "Pitcairn ",
        "Poland ",
        "Portugal",
        "Puerto Rico",
        "Qatar ",
        "Republic of the Congo",
        "Reunion ",
        "Romania ",
        "Russia",
        "Rwanda ",
        "Saint Barthelemy",
        "Saint Helena",
        "Saint Kitts and Nevis",
        "Saint Lucia",
        "Saint Martin",
        "Saint Pierre and Miquelon",
        "Saint Vincent and the Grenadines",
        "Samoa ",
        "San Marino",
        "Sao Tome and Principe",
        "Saudi Arabia ",
        "Senegal ",
        "Serbia ",
        "Seychelles",
        "Sierra Leone",
        "Singapore",
        "Sint Maarten",
        "Slovakia",
        "Slovenia",
        "Solomon Islands",
        "Somalia ",
        "South Africa",
        "South Korea ",
        "South Sudan ",
        "Spain ",
        "Sri Lanka",
        "Sudan ",
        "Suriname",
        "Svalbard and Jan Mayen ",
        "Swaziland ",
        "Sweden ",
        "Switzerland",
        "Syria ",
        "Taiwan",
        "Tajikistan",
        "Tanzania ",
        "Thailand ",
        "Togo ",
        "Tokelau ",
        "Tonga ",
        "Trinidad and Tobago ",
        "Tunisia ",
        "Turkey ",
        "Turkmenistan",
        "Turks and Caicos Islands",
        "Tuvalu ",
        "U.S. Virgin Islands",
        "Uganda ",
        "Ukraine ",
        "United Arab Emirates",
        "United Kingdom ",
        "United States ",
        "Uruguay ",
        "Uzbekistan ",
        "Vanuatu ",
        "Vatican ",
        "Venezuela ",
        "Vietnam ",
        "Wallis and Futuna",
        "Western Sahara",
        "Yemen ",
        "Zambia",
        "Zimbabwe"};

public static String[]  code = new String[]{ "93",
        "355",
        "213",
        "1-684",
        "376",
        "244",
        "1-264",
        "672",
        "1-268",
        "54",
        "374",
        "297",
        "61",
        "43",
        "994",
        "1-242",
        "973",
        "880",
        "1-246",
        "375",
        "32",
        "501",
        "229",
        " 1-441",
        "975",
        "591",
        " 387",
        "267",
        "55",
        "246",
        "1-284",
        "673",
        "359",
        "226",
        "257",
        " 855",
        "237",
        "1",
        "238",
        " 1-345",
        "236",
        "235",
        " 56",
        "86",
        " 61",
        "61",
        "57",
        "269",
        "682",
        " 506",
        "385",
        "53",
        "599",
        "357",
        "420",
        " 243",
        " 45",
        "253",
        "1-767",
        "1-809",
        "670",
        "593",
        "20",
        "503",
        "240",
        "291",
        "372",
        "251",
        "500",
        "298",
        "679",
        "358",
        "33",
        "689",
        "241",
        "220",
        "995",
        "49",
        "233",
        " 350",
        "30",
        "299",
        "1-473",
        "1-671",
        "502",
        "44-1481",
        "224",
        "245",
        "592",
        "509",
        "504",
        "852",
        "36",
        "354",
        "91",
        "62",
        "98",
        "964",
        "353",
        "44-1624",
        "972",
        "39",
        "225",
        "1-876",
        "81",
        "44-1534",
        "962",
        "7",
        "254",
        "686",
        "383",
        "965",
        "996",
        "856",
        "371",
        "961",
        "266",
        "231",
        "218",
        "423",
        "370",
        "352",
        "853",
        "389",
        "261",
        "265",
        "60",
        "960",
        "223",
        "356",
        "692",
        "222",
        "230",
        "262",
        "52",
        "691",
        "373",
        "377",
        "976",
        "382",
        "1-664",
        "212",
        "258",
        "95",
        "264",
        "674",
        "977",
        "31",
        "599",
        "687",
        "64",
        "505",
        "227",
        "234",
        "683",
        "850",
        "1-670",
        "47",
        "968",
        "92",
        "680",
        "970",
        "507",
        "675",
        "595",
        "51",
        "63",
        "64",
        "48",
        "351",
        "1-787",
        "974",
        "242",
        "262",
        "40",
        "7",
        "250",
        "590",
        "290",
        "1-869",
        "1-758",
        "590",
        "508",
        "1-784",
        "685",
        "378",
        "239",
        "966",
        "221",
        "381",
        "248",
        "232",
        "65",
        "1-721",
        "421",
        "386",
        "677",
        "252",
        "27",
        "82",
        "211",
        "34",
        "94",
        "249",
        "597",
        "47",
        "268",
        "46",
        "41",
        "963",
        "886",
        "992",
        "255",
        "66",
        "228",
        "690",
        "676",
        "1-868",
        "216",
        "90",
        "993",
        "1-649",
        "688",
        "1-340",
        "256",
        "380",
        "971",
        "44",
        "1",
        "598",
        "998",
        "678",
        "379",
        "58",
        "84",
        "681",
        "212",
        "967",
        "260",
        "263"

};

public static String[] getCountry() {
    return country;
}

public static String[] getCode() {
    return code;
}
}

そして、これらのクラスを使用する方法は次のとおりです。

     ////GETTING THE COUNTRY AND CODE ARRAY ARE AS FOLLOW:-

         ArrayList<String> codeArrayList = new ArrayList<String>(Arrays.asList(CountryDetails.getCode())); 
         ArrayList<String> countryArrayList = new ArrayList<String>(Arrays.asList(CountryDetails.getCountry())); 


    /////SETTING THE ADAPTER ACCORDING TO THE COUNTRY NAMES

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(SignUpScreen.this, Android.R.layout.simple_list_item_1, countryArrayList);

        YOUR_LIST_VIEW.setAdapter(adapter);///HERE YOUR_LIST_VIEW IS YOUR LISTVIEW NAME

        YOUR_LIST_VIEW.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(this,"COUNTRY NAME==>>"+countryArrayList.get(i),Toast.LENGTH_SHORT+" HERE IS THE COUNTY CODE==>>"+codeArrayList.get(i),Toast.LENGTH_SHORT).show();

            }
        });
1