{
    分享网正式开通,我们为大家提供免费资源,欢迎大家踊跃投稿!

仿京东样式Android 客户端的级联地址选择器

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

添加依赖

项目的 build.gradle 中:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io"}
    }
}

模块的 build.gradle 中:

dependencies {
    ...
    compile 'com.github.chihane:JDAddressSelector:1.1.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();
// frameLayout.addView(view)
// new AlertDialog.Builder(context).setView(view).show()
// ...

BottomDialog

BottomDialog dialog = new BottomDialog(context);
dialog.setOnAddressSelectedListener(listener);
dialog.show();

使用自定义数据源

selector.setAddressProvider(new AddressProvider() {
    @Override
    public void provideProvinces(AddressReceiver<Province> addressReceiver) {
        List<Province> provinces = // blahblahblah 
        addressReceiver.send(provinces);    
    }

    @Override
    public void provideCitiesWith(int provinceId, AddressReceiver<City> addressReceiver) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                List<City> cities = // blahblahblah
                addressReceiver.send(cities);
            }
        }).start();
    }

    @Override
    public void provideCountiesWith(int cityId, AddressReceiver<County> addressReceiver) {
        addressApi.counties(cityId)
                .subscribeOn(Schedulers.io())
                .subscribe(new Action1<List<County>>() {
                    @Override
                    public void call(List<County> counties) {
                        addressReceiver.send(counties);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        addressReceiver.send(null);
                    }
                });
    }

    @Override
    public void provideStreetsWith(int countyId, AddressReceiver<Street> addressReceiver) {
        // blahblahblah 
    }
});

资源均来自第三方,谨慎下载,前往第三方网站下载


米微资源分享网 , 版权所有丨本站资源仅限于学习研究,严禁从事商业或者非法活动!丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:仿京东样式Android 客户端的级联地址选择器
喜欢 ()分享 (0)