如何获取给定国家/地区名称的PHONE ISD代码

时间:2014-04-29 09:46:25

标签: java android

package com.lociiapp;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;

import com.example.imageslideshow.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.Button;

import android.widget.Spinner;
import android.widget.TextView;

public class RegitsraionPage extends Activity {

    private Spinner country;
    TextView textview;
    Button regstraionbutton;
    String countrycode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.registraion);
        country = (Spinner) findViewById(R.id.spinner1);
        textview = (TextView) findViewById(R.id.editText1);
        regstraionbutton = (Button) findViewById(R.id.button1);
        Locale[] locales = Locale.getAvailableLocales();
        ArrayList<String> countries = new ArrayList<String>();
        for (Locale locale : locales) {
            String country = locale.getDisplayCountry();
            countrycode = locale.getCountry();
            if (country.trim().length() > 0 && !countries.contains(country)) {
                countries.add(country);
            }

        }
        Collections.sort(countries);
        for (String country : countries) {
            System.out.println(country);
        }

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
                R.layout.spinner_item, countries);
        // set the view for the Drop down list
        dataAdapter
                .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // set the ArrayAdapter to the spinner
        country.setAdapter(dataAdapter);

        regstraionbutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent myintent = new Intent(RegitsraionPage.this,
                        HomeActivity.class);
                startActivity(myintent);
                // textview.setText(countrycode);

            }
        });
    }

}

这是我的Android代码。我能够在Spring中显示国家名称我想显示onitemselection国家ISD代码。就像我们选择INDIA一样,它应显示+91,如果我们选择美国,则应显示+1

1 个答案:

答案 0 :(得分:0)

Here是您正在寻找的网络服务。