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.EditText;
import android.widget.Spinner;
public class RegitsraionPage extends Activity {
private Spinner country;
EditText editext;
Button regstraionbutton;
@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);
editext = (EditText) findViewById(R.id.editText1);
regstraionbutton = (Button) findViewById(R.id.button1);
GetCountryZipCode();
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);
}
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);
}
});
}
public String GetCountryZipCode() {
String CountryID = "";
String CountryZipCode = "";
TelephonyManager manager = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
// getNetworkCountryIso
CountryID = manager.getSimCountryIso().toUpperCase();
String[] rl = this.getResources().getStringArray(R.array.CountryCodes);
for (int i = 0; i < rl.length; i++) {
String[] g = rl[i].split(",");
if (g[1].trim().equals(CountryID.trim())) {
CountryZipCode = g[0];
break;
}
}
return CountryZipCode;
}
}
这是我的代码,用于在Spinner上使用Locale显示国家名称现在我想设置ISD代码如果我们选择任何国家/地区从国家/地区代码获取ISD代码使用方法GetCountryZipCode()
但我无法在选择上设置值国名请帮忙
String[] rl = this.getResources().getStringArray(R.array.CountryCodes);
这行代码给出。关于选择COuntry代码的国家ISD代码。我已在String.xml
文件中设置了所有COuntry代码及其ISD CODE。SnapShot请在此屏幕中查看我将更清楚我想要的是什么。