Coder Social home page Coder Social logo

multistagepicker's Introduction

MultistagePicker

多层级选择器。默认提供了一个由其实现的**大陆省市区选择器 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.

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.