GithubHelp home page GithubHelp logo

mzdongliang / citypicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from crazyandcoder/citypicker

0.0 1.0 0.0 975 KB

citypicker城市选择器,详细的省市区地址信息,支持仿iOS滚轮实现,一级或者三级列表展示方式。

Java 100.00%

citypicker's Introduction

CityPicker 城市选择器


在实际的项目中一般情况下都需要使用到省市区三级联动地址选择的功能,有的公司是提供接口获取,有的公司则不是,需要自己实现。一开始,我也深受其扰,每次都是要复制一遍,就想能不能打个包出来,供大伙使用。所以自己就封装了一个,不需要自己添加数据源,直接引用即可。这就是CityPicker城市选择器的由来!

功能点


  1. 支持仿iOS滚轮实现、一级城市列表、三级城市列表
  2. 支持多种自定义属性来满足你的需求
  3. 简单的几行代码即可实现城市选择器功能

数据来源


《中华人民共和国国家统计局-最新县及县以上行政区划代码(截止2016年7月31日)》

**数据(维基百科)需翻墙

港澳数据(维基百科)需翻墙

效果展示


仿iOS滚轮实现

城市一级列表展示效果图

省市区三级列表展示效果图

CityPicker使用方法


gradle引用

compile 'liji.library.dev:citypickerview:3.1.13'

代码混淆

#地区3级联动选择器

-keep class com.lljjcoder.**{
	*;
}

-dontwarn demo.**
-keep class demo.**{*;}
-dontwarn net.sourceforge.pinyin4j.**
-keep class net.sourceforge.pinyin4j.**{*;}
-keep class net.sourceforge.pinyin4j.format.**{*;}
-keep class net.sourceforge.pinyin4j.format.exception.**{*;}

举个栗子:

首先需要预加载数据,如我们在AddNewAddressActivity中使用到省市区选择器的话,那么我们需要提前解析本地数据,这样在弹出来的时候不会卡顿,因为本地城市数据很多。


public class AddNewAddressActivity extends Activity {

	//申明对象
	CityPickerView mPicker=new CityPickerView();

    @Override
    public void onCreate() {
        super.onCreate();
        
        //预先加载仿iOS滚轮实现的全部数据
        mPicker.init(this);
        
       
    }
}

然后在需要弹出的地方如点击地区选择button时弹出它,


//添加默认的配置,不需要自己定义,当然也可以自定义相关熟悉,详细属性请看demo
CityConfig cityConfig = new CityConfig.Builder().build();
mPicker.setConfig(cityConfig);

//监听选择点击事件及返回结果
mPicker.setOnCityItemClickListener(new OnCityItemClickListener() {
            @Override
            public void onSelected(ProvinceBean province, CityBean city, DistrictBean district) {
                 
                //省份province               
                //城市city
                //地区district 
            }
            
            @Override
            public void onCancel() {
                ToastUtils.showLongToast(this, "已取消");
            }
        });

		//显示
        mPicker.showCityPicker( );

以上加载是默认属性设置下的选择器,当然我们也可以设置我们自己的样式,详细的属性设置,请看

《详细样式设置属性大全》

返回结果的数据接口

ProvinceBean province, CityBean city, DistrictBean district都是一样的数据结构。

id  //城市code
name //城市名称

其他列表样式使用代码


  1. 城市一级列表样式使用方法及demo
  2. 省市区三级列表使用方法及demo

下个大版本要做的


  1. 完成仿京东格式的选择器样式
  2. 更新数据源2017版

更新说明


V3.1.13版本更新内容(2018.09.10)

  1. 发布3.1.13版本,修复#112,#113bug

历史更新说明

专属QQ群,欢迎加入!


QQ群:417846442

赞赏


如果你喜欢 citypicker 这个开源库,感觉 citypicker 帮助到了你,可以点右上角 "Star" 支持一下 谢谢!,你也还可以扫描下面的二维码~ 请作者喝一杯牛奶,让作者更有动力写出更好的开源库服务大家。^_^

赞赏的伙计,请注明你们的昵称,请留下你们的联系方式(最好是GitHub地址),谢谢合作 ^_^ 。

赞赏人员列表


赞赏的人

citypicker's People

Contributors

crazyandcoder avatar

Watchers

 avatar

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.