Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

地址选择器设置默认值建议增加ID设置 #39

Closed
xoptimal opened this issue Aug 19, 2016 · 2 comments
Closed

地址选择器设置默认值建议增加ID设置 #39

xoptimal opened this issue Aug 19, 2016 · 2 comments
Assignees

Comments

@xoptimal
Copy link

picker.setSelectedItem("贵州", "贵阳", "花溪");

picker.setSelectedItem("520000", "520100" "520111");

@liyujiang-gzu
Copy link
Member

1.5.X版本已经支持传入对象,详见demo

@xoptimal
Copy link
Author

xoptimal commented May 26, 2017

你好, 为什么是对象..... 我想说直接支持ID查找 .....

    public void onAddressPicker(View view) {
        AddressPickTask task = new AddressPickTask(this);
        task.setHideProvince(false);
        task.setHideCounty(false);
        task.setCallback(new AddressPickTask.Callback() {
            @Override
            public void onAddressInitFailed() {
                showToast("数据初始化失败");
            }

            @Override
            public void onAddressPicked(Province province, City city, County county) {
                if (county == null) {
                    showToast(province.getAreaName() + city.getAreaName());
                } else {
                    showToast(province.getAreaName() + city.getAreaName() + county.getAreaName());
                }
            }
        });
        task.execute("贵州", "毕节", "纳雍");
    }

    public void onAddress2Picker(View view) {
        try {
            ArrayList<Province> data = new ArrayList<>();
            String json = ConvertUtils.toString(getAssets().open("city2.json"));
            data.addAll(JSON.parseArray(json, Province.class));
            AddressPicker picker = new AddressPicker(this, data);
            picker.setShadowVisible(true);
            picker.setHideProvince(true);
            picker.setSelectedItem("贵州", "贵阳", "花溪");
            picker.setOnAddressPickListener(new AddressPicker.OnAddressPickListener() {
                @Override
                public void onAddressPicked(Province province, City city, County county) {
                    showToast("province : " + province + ", city: " + city + ", county: " + county);
                }
            });
            picker.show();
        } catch (Exception e) {
            showToast(LogUtils.toStackTraceString(e));
        }
    }


    public void onAddress3Picker(View view) {
        AddressPickTask task = new AddressPickTask(this);
        task.setHideCounty(true);
        task.setCallback(new AddressPickTask.Callback() {
            @Override
            public void onAddressInitFailed() {
                showToast("数据初始化失败");
            }

            @Override
            public void onAddressPicked(Province province, City city, County county) {
                showToast(province.getAreaName() + " " + city.getAreaName());
            }
        });
        task.execute("四川", "阿坝");
    }

已知服务器存储的是名称对应的ID, eg. 贵州=520000 , 一般情况下, 服务器是返回 520000", "520100" "520111" ,

转换对象是直接 New Province province, City city, County county ... 然后传入ID

我觉得这层可以封装呀 .... 直接接收传入ID , eg. picker.setSelectedItemID("520000", "520100" "520111");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants