Android 多层级选择器,地址选择器,省市区选择器

MultistagePicker

项目地址:stingzhan/MultistagePicker 

简介: Android 多层级选择器,地址选择器,省市区选择器

更多:作者   提 Bug   

标签:

多层级选择器。默认提供了一个由其实现的中国大陆省市区选择器 RegionPicker

正在上传…重新上传取消

开始使用

在项目根目录中的 build.gralde 文件中:

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

在 Module 中的 build.graldle 文件中添加依赖:

dependencies {
    implementation 'com.github.stingzhan:MultistagePicker:1.0.0'
}

用例

Step1: 创建一个 MultistagePickerDataProvider 为选择器提供数据,示例:

    val options = mapOf(
        "业务相关" to listOf("业务员", "区域经理", "业务经理", "业务总监"),
        "销售相关" to listOf("销售员", "柜长", "销售经理", "展厅经理", "销售总监")
    )

    val dataProvider = object : MultistagePickerDataProvider() {
        private val keys = listOf("Key1", "Key2")

        override fun stageKeys(): List<String> {
            return keys
        }

        override fun stageData(stageKey: String, upperStageSelectedOptions: Map<String, String>): List<String>? {
            return when (stageKey) {
                "Key1" -> options.keys.toList()
                "Key2" -> {
                    val key = upperStageSelectedOptions["Key1"]
                    options[key]
                }
                else -> null
            }
        }
    }

Step2: 创建一个选择器,示例:

    val simplePicker = MultistagePickerDialog(this, dataProvider)
    simplePicker.setOnPickCompletedListener { selectedOptions ->
        // selectedOptions 存放着选取结果
    }

Step3: 弹出选择器, 示例:

    simplePicker.show()

省市区选择器使用:

    val regionPicker = RegionPicker(this)
    regionPicker.setOnAddressPickSuccessListener { region ->
        Log.i("ResultTag", "结果: ${region.province} - ${region.city} - ${region.district}")
    }
    regionPicker.show()

设置预选中的省市区值:

    regionPicker.setDefaultRegion(Region("广东省", "深圳市", "龙岗区"))

Sample screenshots

 

License


Copyright 2018 stingzhan. https://github.com/stingzhan

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值