GithubHelp home page GithubHelp logo

addressselector's Introduction

AddressSelector

一个 Android 版京东手机客户端(当前版本V1..0.0 )风格的级联地址选择器。 image

添加依赖

build.gradle 中:

dependencies {
    ...
    compile 'com.smartTop:jd-address:1.0.3'
}

使用方法

AddressSelector selector = new AddressSelector(context);
selector.setOnAddressSelectedListener(new AddressSelector.OnAddressSelectedListener() {
    @Override
    public void onAddressSelected(Province province, City city, County county, Street street) {
        // blahblahblah
    }
});
        
View view = selector.getView();
content.addView(view);

默认的样式

image

自定义样式

//设置字体的大小

selector.setTextSize(14);

//设置指示器的背景颜色

selector.setIndicatorBackgroundColor("#00ff00");

selector.setIndicatorBackgroundColor(android.R.color.holo_orange_light);

//设置字体的背景

selector.setBackgroundColor(android.R.color.holo_red_light);

//设置字体获得焦点的颜色

selector.setTextSelectedColor(android.R.color.holo_orange_light);

//设置字体没有获得焦点的颜色

selector.setTextUnSelectedColor(android.R.color.holo_blue_light);

//自定义dialog的样式

 dialog.setTextSize(14);//设置字体的大小
 dialog.setIndicatorBackgroundColor(android.R.color.holo_orange_light);//设置指示器的颜色
 dialog.setTextSelectedColor(android.R.color.holo_orange_light);//设置字体获得焦点的颜色
 dialog.setTextUnSelectedColor(android.R.color.holo_blue_light);//设置字体没有获得焦点的颜色
 dialog.setDisplaySelectorArea("31",1,"2704",1,"2711",0,"15582",1);//设置已选中的地区(第一个参数 省份的code,第二个参数 省份在列表中的位置,第三个参数 城市的code 第四个参数 城市在列表中的位置,...)
 效果图

image

BottomDialog 弹出地址选择器的dialog的用法及回调

BottomDialog dialog = new BottomDialog(context);
dialog.setOnAddressSelectedListener(this);
dialog.setDialogDismisListener(this);
dialog.setSelectorAreaPositionListener(this);
dialog.show();

   @Override
    public void onAddressSelected(Province province, City city, County county, Street street) {
        provinceCode = (province == null ? "" : province.code);
        cityCode = (city == null ? "" : city.code);
        countyCode = (county == null ? "" : county.code);
        streetCode = (street == null ? "" : street.code);
        LogUtil.d("数据", "省份id=" + provinceCode);
        LogUtil.d("数据", "城市id=" + cityCode);
        LogUtil.d("数据", "乡镇id=" + countyCode);
        LogUtil.d("数据", "街道id=" + streetCode);
        String s = (province == null ? "" : province.name) + (city == null ? "" : city.name) + (county == null ? "" : county.name) +
                (street == null ? "" : street.name);
        tv_selector_area.setText(s);
        if (dialog != null) {
            dialog.dismiss();
        }
    }

    @Override
    public void dialogclose() {
        if(dialog!=null){
            dialog.dismiss();
        }
    }
    选中的地区在列表中的位置
    @Override
    public void selectorAreaPosition(int provincePosition, int cityPosition, int countyPosition, int streetPosition) {
            this.provincePosition = provincePosition;
            this.cityPosition = cityPosition;
            this.countyPosition = countyPosition;
            this.streetPosition = streetPosition;
            LogUtil.d("数据", "省份位置=" + provincePosition);
            LogUtil.d("数据", "城市位置=" + cityPosition);
            LogUtil.d("数据", "乡镇位置=" + countyPosition);
            LogUtil.d("数据", "街道位置=" + streetPosition);
        }

有朋友问,怎么使用自己的数据源,这里我说明一下,因为我的数据库里的地址表,省,市,区,县,镇,都是用同一个表,根据parentId来查询的。

想用自己的数据源,就需要把自己的数据源里,各个字段与我的数据源里字段一一对应(id, parentId, code, name),分别对应的中文意思(id,父id(可根据父id查询下一级),地址编码,中文名字)

然后在你的项目里的assets目录下,放上你的数据库,名字一定是"address.db".

如果你用的是android studio 应该放在

image

在源数据库里要添加一个数据 AdressBean.ChangeRecordsBean changeRecordsBean = new AdressBean.ChangeRecordsBean();

    changeRecordsBean.parentId = 0;

    changeRecordsBean.name = "测试省";

    changeRecordsBean.id = 35;

    addressDictManager.inserddress(changeRecordsBean);

image

还可以进行已下操作 增加一个数据 inserddress(AdressBean.ChangeRecordsBean adress) 增加一个集合insertAddress(List<AdressBean.ChangeRecordsBean> list)

更新数据 updateAddressInfo(AdressBean.ChangeRecordsBean adress)

查找数据 getAddressList()

获取省市列表 getProvinceList()

根据省市id 获取城市列表 getCityList(int provinceId)

获取城市对应的区,乡镇列表 getCountyList(int cityId)

获取区,乡镇对应的街道列表 getStreetList(int countyId)

查找消息临时列表中是否存在这一条记录 isExist()

最近在我博客上有人问我,能不能加一个功能,就是记住选择后的地址,点击编辑地址的时候,可以直接显示了。
 dialog.setDisplaySelectorArea("31",1,"2704",1,"2711",0,"15582",1);//设置已选中的地区(第一个参数 省份的code,第二个参数 省份在列表中的位置,第三个参数 城市的code 第四个参数 城市在列表中的位置,...)
  用法:
          /**
           * 根据code 来显示选择过的地区
           */
          private void getSelectedArea(){
              //根据省份的code,从数据库里查询省份的名字
              String province = addressDictManager.getProvince(provinceCode);
              //根据城市的code,从数据库里查询城市的名字
              String city = addressDictManager.getCity(cityCode);
              //根据乡镇的code,从数据库里查询乡镇的名字
              String county = addressDictManager.getCounty(countyCode);
              //根据街道的code,从数据库里查询街道的名字
              String street = addressDictManager.getStreet(streetCode);

              LogUtil.d("数据", "省份=" + province);
              LogUtil.d("数据", "城市=" + city);
              LogUtil.d("数据", "乡镇=" + county);
              LogUtil.d("数据", "街道=" + street);
          }

关于我

smartTop

addressselector's People

Contributors

smarttop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

addressselector's Issues

不想选择街道

您好,我想请问一下,如果我不想选择街道..要怎么修改代码的....

有时候报空指针

提示在onAddressSelectedListener的onAddressSelected方法中获取那四个参数的属性的时候

项目导入异常

您好,我在直接使用源码的时候遇到点问题,我AS 1.5的
image
请问怎么解决这个问题?
改下v7包的依赖,库的依赖和app里的依赖不一致

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.