1.设置个点击事件
//点击事件
dizhi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
initCityPicker();
}
});
2.
//三级
private void initCityPicker() {
cityPicker = new CityPicker.Builder(XZReplaceActivity.this)
//滚轮文字的大小
.textSize(14)
.title("地址选择")
.titleBackgroundColor("#FFFFFF")
.confirTextColor("#696969")
.cancelTextColor("#696969")
.province("江苏省")
.city("常州市")
.district("天宁区")
.textColor(Color.parseColor("#000000"))
.provinceCyclic(true)
.cityCyclic(false)
.districtCyclic(false)
.visibleItemsCount(7)
.itemPadding(10)
.onlyShowProvinceAndCity(false)
.build();
cityPicker.show();
//监听方法,获取选择结果
cityPicker.setOnCityItemClickListener(new CityPicker.OnCityItemClickListener() {
@Override
public void onSelected(String... citySelected) {
//省份
province = citySelected[0];
//城市
city = citySelected[1];
//区县(如果设定了两级联动,那么该项返回空)
district = citySelected[2];
//邮编
code = citySelected[3];
dizhi.setText(province.trim() + "-" + city.trim() + "-" + district.trim());
}
});
3.依赖:
implementation 'liji.library.dev:citypickerview:0.7.0'