二级地址选择器
@OnClick({R.id.rl_time})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.rl_time:
getAddressSelect(view);
break;
}
}
private void getAddressSelect(View v) {
//判断输入法的隐藏状态
InputMethodManager imm =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null && imm.isActive()) {
imm.hideSoftInputFromWindow(v.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
selectAddress();//调用CityPicker选取区域
}
}
/**
* 地址选择器
*/
private void selectAddress() {
CityPicker cityPicker = new CityPicker.Builder(this)
.textSize(16)
.titleBackgroundColor("#FFFFFF")
.confirTextColor("#171923")
.cancelTextColor("#171923")
.province("北京市")
.city("北京市")
// .district("朝阳区")
.onlyShowProvinceAndCity(true)
.textColor(Color.parseColor("#171923"))
.provinceCyclic(true)
.cityCyclic(false)
// .districtCyclic(false)
.visibleItemsCount(7)
.itemPadding(10)
.build();
cityPicker.show();
/*监听方法,获取选择结果*/
cityPicker.setOnCityItemClickListener(new CityPicker.OnCityItemClickListener() {
@SuppressLint("SetTextI18n")
@Override
public void onSelected(String... citySelected) {
//省份
String province = citySelected[0];
//城市
String city = citySelected[1];
//区县(如果设定了两级联动,那么该项返回空)
// district = citySelected[2];
//为TextView赋值
// mBtnSave.setTextColor(getColorById(R.color.red));
// mBtnSave.setEnabled(true);
tvGetTime.setText(province.trim() + "-" + city.trim());
}
});
}