簡體   English   中英

如何獲取給定國家名稱的PHONE ISD代碼

[英]how to get PHONE ISD code for given country Name

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代碼。 我可以在春季顯示國家名稱,我想顯示onitemselection國家ISD代碼。 就像我們選擇INDIA它應該顯示+91 ;如果我們選擇美國時,它應該顯示+1

是您要查找的Web服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM