用Android获取一个国家的州

用Android获取一个国家的州,android,locale,states,Android,Locale,States,当用户从Java的Locale类中选择一个特定的国家时,是否可以获得所有状态的列表?我可以从Locale类中获得所有国家的列表。但是Locale类不提供状态。他们还有别的办法吗?还是有一个我可以利用的web服务 任何帮助都将不胜感激。提前感谢:)除了使用谷歌地图API,这可能需要你有一个全职连接。。。有一个包含所有局部变量的数据集称为。您可以在SqLite数据库中使用它。尝试以下方法: import java.text.Collator; import java.util.Arr

当用户从Java的Locale类中选择一个特定的国家时,是否可以获得所有状态的列表?我可以从Locale类中获得所有国家的列表。但是Locale类不提供状态。他们还有别的办法吗?还是有一个我可以利用的web服务


任何帮助都将不胜感激。提前感谢:)

除了使用谷歌地图API,这可能需要你有一个全职连接。。。有一个包含所有局部变量的数据集称为。您可以在SqLite数据库中使用它。

尝试以下方法:

    import java.text.Collator;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.List;
    import java.util.Locale;

    public class Country  {

    public void getCountries{
    List<Country> countries = new ArrayList<Country>();

    Locale[] locales = Locale.getAvailableLocales();
    for (Locale locale : locales) {
      String iso = locale.getISO3Country();
      String code = locale.getCountry();
      String name = locale.getDisplayCountry();

      if (!"".equals(iso) && !"".equals(code) && !"".equals(name)) {
        countries.add(new Country(iso, code, name));
      }
    }

    Collections.sort(countries, new CountryComparator());
    for (Country country : countries) {
      System.out.println(country);
    }
  }
}

class CountryComparator implements Comparator<Country> {
  private Comparator comparator;

  CountryComparator() {
    comparator = Collator.getInstance();
  }

  public int compare(Country o1, Country o2) {
    return comparator.compare(o1.name, o2.name);
  }
}

class Country {
  private String iso;

  private String code;

  public String name;

  Country(String iso, String code, String name) {
    this.iso = iso;
    this.code = code;
    this.name = name;
  }

  public String toString() {
    return iso + " - " + code + " - " + name.toUpperCase();
  }
}
import java.text.Collator;
导入java.util.ArrayList;
导入java.util.Collections;
导入java.util.Comparator;
导入java.util.List;
导入java.util.Locale;
公营国家{
各国的公共卫生{
列表国家=新的ArrayList();
Locale[]locales=Locale.getAvailableLocales();
for(区域设置:区域设置){
字符串iso=locale.getISO3Country();
字符串代码=locale.getCountry();
字符串名称=locale.getDisplayCountry();
如果(!“”.equals(iso)和&&&!“”.equals(代码)和&&&&!“”.equals(名称)){
添加(新国家(iso、代码、名称));
}
}
Collections.sort(countries,newcountrycomparator());
适用于(国家:国家){
System.out.println(国家);
}
}
}
类CountryComparator实现Comparator{
专用比较器;
CountryComparator(){
comparator=Collator.getInstance();
}
公共整数比较(国家o1,国家o2){
返回comparator.compare(o1.name,o2.name);
}
}
阶级国家{
私有字符串iso;
私有字符串码;
公共字符串名称;
国家(字符串iso、字符串代码、字符串名称){
这是iso=iso;
this.code=代码;
this.name=名称;
}
公共字符串toString(){
返回iso+“-”+code+“-”+name.toUpperCase();
}
}

看,这可能是这个api对你的帮助很多:)但是你能解释一下我已经知道的代码吗getCountry()函数rest我不确定这个问题询问的所有州的列表在哪里?如何使用country获得州的列表?