超级简单的三级联动

效果
超级简单的三级联动_第1张图片
依赖

implementation 'liji.library.dev:citypickerview:0.1.0'

代码块

随便写一个点击事件把下面代码粘里面

CityPickerView cityPickerView = new CityPickerView(this);
                cityPickerView.setOnCityItemClickListener(new CityPickerView.OnCityItemClickListener() {
                    @Override
                    public void onSelected(String... citySelected) {
                        //省份
                        String province = citySelected[0];
                        //城市
                        String city = citySelected[1];
                        //区县
                        String district = citySelected[2];
                        //邮编
                        String code = citySelected[3];
                        //控件自己写两个edittext或者Xedittext用来显示文本代替下面两个个控件ID
                        //address_new_address用来展示地址
                        //address_new_zipcode用来展示邮编
                        address_new_address.setText(province + "-" + city + "-" + district);
                        address_new_zipcode.setText(code);
                    }
                });
                cityPickerView.show();

展示效果

超级简单的三级联动_第2张图片

你可能感兴趣的:(超级简单的三级联动)