compile 'liji.library.dev:citypickerview:0.7.0'
private void initListener() {
address.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectAddress();
}
});
}
private void selectAddress() {
CityPicker cityPicker =new CityPicker.Builder(MainActivity.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) {
//省份
String province = citySelected[0];
//城市
String city = citySelected[1];
//区县(如果设定了两级联动,那么该项返回空)
String district = citySelected[2];
//邮编
String code = citySelected[3];
//为TextView赋值
address.setText(province.trim() +"-" + city.trim() +"-" + district.trim());
}
});
}