{"id":26497534,"url":"https://github.com/duanhong169/pickerview","last_synced_at":"2025-08-25T06:36:02.289Z","repository":{"id":144518917,"uuid":"97369751","full_name":"duanhong169/PickerView","owner":"duanhong169","description":"🕘 Android滚动选择器（省市区联动选择、日期选择、时间选择）","archived":false,"fork":false,"pushed_at":"2020-07-19T07:34:28.000Z","size":3920,"stargazers_count":259,"open_issues_count":7,"forks_count":43,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-09T22:12:54.204Z","etag":null,"topics":["android","city-picker","date-picker","number-picker","pickerview","time-picker"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/duanhong169.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-16T08:15:34.000Z","updated_at":"2025-04-02T06:18:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"197cc6a7-f9f5-4ed0-94fa-8d78fa61ea72","html_url":"https://github.com/duanhong169/PickerView","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duanhong169%2FPickerView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duanhong169%2FPickerView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duanhong169%2FPickerView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duanhong169%2FPickerView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/duanhong169","download_url":"https://codeload.github.com/duanhong169/PickerView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119292,"owners_count":21050755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","city-picker","date-picker","number-picker","pickerview","time-picker"],"created_at":"2025-03-20T13:43:07.785Z","updated_at":"2025-04-09T22:13:01.393Z","avatar_url":"https://github.com/duanhong169.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PickerView [![gitHub release](https://img.shields.io/github/release/duanhong169/PickerView.svg?style=social)](https://github.com/duanhong169/PickerView/releases) [![platform](https://img.shields.io/badge/platform-android-brightgreen.svg)](https://developer.android.com/index.html) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-PickerView-green.svg?style=flat)](https://android-arsenal.com/details/1/7056) [![license](https://img.shields.io/badge/license-Apache%202-green.svg)](https://github.com/duanhong169/PickerView/blob/master/LICENSE) [![Build status](https://build.appcenter.ms/v0.1/apps/82a51128-aa71-4c56-9114-4170c51cb899/branches/master/badge)](https://appcenter.ms)\n\nAndroid滚动选择器\n\n\u003cimg src='art/default.gif' height='500px'/\u003e \u003cimg src='art/division.gif' height='500px'/\u003e\n\u003cimg src='art/date_time.gif' height='500px'/\u003e \u003cimg src='art/curved.gif' height='500px'/\u003e\n\u003cimg src='art/date_time_dialog.png' height='500px'/\u003e \u003cimg src='art/division_dialog.png' height='500px'/\u003e\n\n## 使用方法\n\n### 1. 添加依赖\n\n\u003e 注：${latestVersion}请替换为当前最新版本号，见[releases](https://github.com/duanhong169/PickerView/releases)。\n\ngradle：\n\t\n```groovy\nimplementation 'com.github.duanhong169:picker-view:${latestVersion}'\n```\n\nmaven：\n\t\n```xml\n\u003cdependency\u003e\n\t\u003cgroupId\u003ecom.github.duanhong169\u003c/groupId\u003e\n\t\u003cartifactId\u003epicker-view\u003c/artifactId\u003e\n\t\u003cversion\u003e${latestVersion}\u003c/version\u003e\n\t\u003ctype\u003epom\u003c/type\u003e\n\u003c/dependency\u003e\n```\n\n### 2. 集成到项目中\n\n#### 2.1 集成PickerView\n\n添加到layout文件中：\n\n```xml\n\u003ctop.defaults.view.PickerView\n\tandroid:id=\"@+id/pickerView\"\n\tandroid:layout_width=\"match_parent\"\n\tandroid:layout_height=\"wrap_content\"/\u003e\n```\n\n##### 使用列表作为数据源\n\n```java\nList\u003cItem\u003e items = new ArrayList\u003c\u003e();\nfor (int i = 0; i \u003c 42; i++) {\n    items.add(new Item(\"Item \" + i));\n}\n\npickerView.setItems(Item.sampleItems(), item -\u003e textView.setText(item.getText()));\n```\n\n##### 实现Adapter作为数据源\n\n配置数据源：\n\n```java\nPickerView.Adapter adapter = new PickerView.Adapter() {\n\n    @Override\n    public int getItemCount() {\n        return 42;\n    }\n\n    @Override\n    public String getText(int index) {\n        return \"Item \" + index;\n    }\n};\npickerView.setAdapter(adapter);\n```\n\n监听选择事件：\n\n```java\npickerView.setOnSelectedItemChangedListener((pickerView, previousPosition, selectedItemPosition) -\u003e \n        textView.setText(pickerView.getAdapter().getText(selectedItemPosition)));\n```\n\n#### 2.2 集成DivisionPickerView\n\n添加到layout文件中：\n\n```xml\n\u003ctop.defaults.view.DivisionPickerView\n    android:id=\"@+id/divisionPicker\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\"\n    app:preferredMaxOffsetItemCount=\"4\"\n    android:background=\"#e7e7e7\"/\u003e\n```\n\n构建省市区数据源：\n\n\u003e 参考[Divisions.java](app/src/main/java/top/defaults/pickerviewapp/Divisions.java)\n\n设置数据源并监听选择事件\n\n```java\nfinal List\u003cDivisionModel\u003e divisions = Divisions.get(this);\ndivisionPicker.setDivisions(divisions);\ndivisionPicker.setOnSelectedDateChangedListener(division -\u003e textView.setText(Division.Helper.getCanonicalName(division)));\n```\n\n#### 2.3 集成DateTimePickerView\n\n添加到layout文件中：\n\n```xml\n\u003ctop.defaults.view.DateTimePickerView\n    android:id=\"@+id/datePickerView\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\"\n    app:preferredMaxOffsetItemCount=\"3\"\n    app:textSize=\"18sp\"\n    app:type=\"dateTime\"\n    app:minutesInterval=\"fifteen\"\n    app:curved=\"true\"\n    android:background=\"#e7e7e7\"/\u003e\n```\n\n设置初始日期：\n\n```java\ndateTimePickerView.setStartDate(Calendar.getInstance());\n// 注意：月份是从0开始计数的\ndateTimePickerView.setSelectedDate(new GregorianCalendar(2017, 6, 27, 21, 30));\n```\n\n监听选择事件：\n\n```java\ndateTimePickerView.setOnSelectedDateChangedListener(new DateTimePickerView.OnSelectedDateChangedListener() {\n    @Override\n    public void onSelectedDateChanged(Calendar date) {\n        int year = date.get(Calendar.YEAR);\n        int month = date.get(Calendar.MONTH);\n        int dayOfMonth = date.get(Calendar.DAY_OF_MONTH);\n        int hour = date.get(Calendar.HOUR_OF_DAY);\n        int minute = date.get(Calendar.MINUTE);\n        String dateString = String.format(Locale.getDefault(), \"%d年%02d月%02d日%02d时%02d分\", year, month + 1, dayOfMonth, hour, minute);\n        textView.setText(dateString);\n        Log.d(TAG, \"new date: \" + dateString);\n    }\n});\n```\n\n更详细的使用方法请参见示例。\n\n## License\n\nCopyright 2018 Hong Duan\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduanhong169%2Fpickerview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fduanhong169%2Fpickerview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduanhong169%2Fpickerview/lists"}