Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中基于区域设置的地址格式_Android_Street Address - Fatal编程技术网

android中基于区域设置的地址格式

android中基于区域设置的地址格式,android,street-address,Android,Street Address,嗨,在我的应用程序中,我需要根据用户设置的语言环境显示输入地址。有没有人在Android平台上进行过格式化或地址格式化,或者有任何指针进行过格式化。我在其他平台上做了相当多的本地化工作。以下是Android本地化指南: 一种方法是使用本地化资源来存储MessageFormat字符串,这些字符串对应于所需的每个语言环境的地址布局。从这里开始,您将需要对全局地址块标准的引用,并为您需要的每个语言环境创建格式字符串。签出。项目中有两个模块:android和:common。您应该只需要:common来格

嗨,在我的应用程序中,我需要根据用户设置的语言环境显示输入地址。有没有人在Android平台上进行过格式化或地址格式化,或者有任何指针进行过格式化。

我在其他平台上做了相当多的本地化工作。以下是Android本地化指南:

一种方法是使用本地化资源来存储MessageFormat字符串,这些字符串对应于所需的每个语言环境的地址布局。从这里开始,您将需要对全局地址块标准的引用,并为您需要的每个语言环境创建格式字符串。

签出。项目中有两个模块:android和:common。您应该只需要:common来格式化地址以实现区域设置感知显示

import android.location.Address;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.google.i18n.addressinput.common.AddressData;
import com.google.i18n.addressinput.common.FormOptions;
import com.google.i18n.addressinput.common.FormatInterpreter;
...
public static String getFormattedAddress(@NonNull final Address address, 
                                         @NonNull final String regionCode) {
    final FormatInterpreter formatInterpreter
            = new FormatInterpreter(new FormOptions().createSnapshot());
    final AddressData addressData = (new AddressData.Builder()
            .setAddress(address.getThoroughfare())
            .setLocality(address.getLocality())
            .setAdminArea(address.getAdminArea())
            .setPostalCode(address.getPostalCode())
            .setCountry(regionCode) // REQUIRED
            .build());
    // Fetch the address lines using getEnvelopeAddress,
    List<String> addressFragments = formatInterpreter.getEnvelopeAddress(addressData);
    // join them, and send them to the thread.
    return TextUtils.join(System.getProperty("line.separator"),
            addressFragments);
}
导入android.location.Address;
导入android.support.annotation.NonNull;
导入android.text.TextUtils;
导入com.google.i18n.addressinput.common.AddressData;
导入com.google.i18n.addressinput.common.FormOptions;
导入com.google.i18n.addressinput.common.format解释器;
...
公共静态字符串getFormattedAddress(@NonNull final Address),
@非空的最终字符串(区域代码){
最终格式解释器格式解释器
=新格式解释器(新格式选项().createSnapshot());
final AddressData AddressData=(new AddressData.Builder()
.setAddress(address.getthoroughure())
.setLocality(地址.getLocality())
.setAdminArea(地址.getAdminArea())
.setPostalCode(地址.getPostalCode())
.setCountry(regionCode)//必需
.build());
//使用GetEnvelopedAddress获取地址行,
List addressFragments=formatexplorer.getEnvelopedAddress(addressData);
//加入它们,并将它们发送到线程。
返回TextUtils.join(System.getProperty(“line.separator”),
地址(碎片);
}
注意:regionCode必须是有效的iso2国家代码,因为格式解释器从中提取地址格式。(如果您有兴趣,请参阅格式列表。)

设置地址的2字母CLDR区域代码;看见 AddressData#getPostalCountry()。与传递给 地区代码不能为空

例子:美国

栗子街801号
密苏里州圣路易斯市,邮编63101

示例:JP

〒1600023
西新竹
3-2-11东京西岛新宿


谢谢,我指的是同样的android本地化,它有地址API,但没有根据所选的区域设置提供地址格式。我认为原因是已经输入的邮政地址“属于”某个区域设置,并且有固定的格式设置方式。例如,按照德国惯例或其他方式表达美国的邮政地址就没有多大意义。如果您正在访问ContactsContract数据库,则只需使用StructuredPostal实体的格式化地址字段。在这种情况下,他们使用类似于我建议的方法格式化地址行。不确定是否有更简单的方法。我可以知道这个问题的-1评级的原因吗。我一直在搜索这种库,非常感谢你的回答!