|
| 1 | + |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This is a library for android to pick date or options like IOS system WheelView widget. |
| 6 | +and support for the linkage, dialog . It's very easy to use , and you also can customize layout, which make it very customizable. |
| 7 | + |
| 8 | + |
| 9 | +* there are two options called OptionsPickerView and TimePickerView |
| 10 | + |
| 11 | +* OptionsPickerView supports three levels of linkage |
| 12 | + |
| 13 | +* TimePickerView support selection date range |
| 14 | + |
| 15 | +* support "year, month, day, hour, minute, second", "provincial, city, district" and other options of the unit (label) show or hide and customize label. |
| 16 | + |
| 17 | +* supports custom text, color, text size, etc. |
| 18 | + |
| 19 | +* If Item text length is too long, it will be adapted to the length of the Item to avoid the problem of incomplete display |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +# How to use |
| 24 | + |
| 25 | + |
| 26 | +## 1.Add the dependency: |
| 27 | + |
| 28 | +### Gradle |
| 29 | + |
| 30 | +```java |
| 31 | +compile 'com.contrarywind:Android-PickerView:3.1.1' |
| 32 | +``` |
| 33 | + |
| 34 | +###Maven |
| 35 | + |
| 36 | +``` |
| 37 | +<dependency> |
| 38 | +<groupId>com.contrarywind</groupId> |
| 39 | +<artifactId>Android-PickerView</artifactId> |
| 40 | +<version>3.1.1</version> |
| 41 | +<type>pom</type> |
| 42 | +</dependency> |
| 43 | +``` |
| 44 | + |
| 45 | +## 2.Add the following code in your Activity: |
| 46 | + |
| 47 | +```java |
| 48 | +//TimePicker |
| 49 | + pvTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() { |
| 50 | + @Override |
| 51 | + public void onTimeSelect(Date date,View v) {//Callback |
| 52 | + tvTime.setText(getTime(date)); |
| 53 | + } |
| 54 | + }) |
| 55 | + .build(); |
| 56 | + pvTime.show(); |
| 57 | +``` |
| 58 | + |
| 59 | +```java |
| 60 | +//OptionsPicker |
| 61 | + pvOptions = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() { |
| 62 | + @Override |
| 63 | + public void onOptionsSelect(int options1, int option2, int options3 ,View v) { |
| 64 | + ////Callback |
| 65 | + String tx = options1Items.get(options1).getPickerViewText() |
| 66 | + + options2Items.get(options1).get(option2) |
| 67 | + + options3Items.get(options1).get(option2).get(options3).getPickerViewText(); |
| 68 | + tvOptions.setText(tx); |
| 69 | + } |
| 70 | + }).build(); |
| 71 | + |
| 72 | + //pvOptions.setPicker(options1Items); |
| 73 | + //pvOptions.setPicker(options1Items, options2Items); |
| 74 | + pvOptions.setPicker(options1Items, options2Items, options3Items); |
| 75 | + pvOptions.show(); |
| 76 | +``` |
| 77 | +## Just so easy ~ |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +If the default style does not meet your expectations, You can also customize attributes to apply |
| 82 | + |
| 83 | +## Customize Useage: |
| 84 | +```java |
| 85 | + Calendar selectedDate = Calendar.getInstance(); |
| 86 | + Calendar startDate = Calendar.getInstance(); |
| 87 | + startDate.set(2013,1,1); |
| 88 | + Calendar endDate = Calendar.getInstance(); |
| 89 | + endDate.set(2020,1,1); |
| 90 | + |
| 91 | + pvTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() { |
| 92 | + @Override |
| 93 | + public void onTimeSelect(Date date,View v) {//Callback |
| 94 | + tvTime.setText(getTime(date)); |
| 95 | + } |
| 96 | + }) |
| 97 | + .setType(TimePickerView.Type.ALL)//default all |
| 98 | + .setCancelText("Cancel") |
| 99 | + .setSubmitText("Sure") |
| 100 | + .setContentSize(18) |
| 101 | + .setTitleSize(20) |
| 102 | + .setTitleText("Title") |
| 103 | + .setOutSideCancelable(false)// default is true |
| 104 | + .isCyclic(true)// default is false |
| 105 | + .setTitleColor(Color.BLACK) |
| 106 | + .setSubmitColor(Color.BLUE) |
| 107 | + .setCancelColor(Color.BLUE) |
| 108 | + .setTitleBgColor(0xFF666666)//Night mode |
| 109 | + .setBgColor(0xFF333333)//Night mode |
| 110 | + .setRange(calendar.get(Calendar.YEAR) - 20, calendar.get(Calendar.YEAR) + 20)//default 1900-2100 years |
| 111 | + .setDate(selectedDate)// default is System time |
| 112 | + .setRangDate(startDate,endDate) |
| 113 | + .setLabel("year","month","day","hours","mins","seconds") |
| 114 | + .build(); |
| 115 | +``` |
| 116 | + |
| 117 | +```java |
| 118 | +pvOptions = new OptionsPickerView.Builder(this, new OptionsPickerView.OnOptionsSelectListener() { |
| 119 | + @Override |
| 120 | + public void onOptionsSelect(int options1, int option2, int options3 ,View v) { |
| 121 | + ////Callback |
| 122 | + String tx = options1Items.get(options1).getPickerViewText() |
| 123 | + + options2Items.get(options1).get(option2) |
| 124 | + + options3Items.get(options1).get(option2).get(options3).getPickerViewText(); |
| 125 | + tvOptions.setText(tx); |
| 126 | + } |
| 127 | + }) |
| 128 | + .setSubmitText("sure") |
| 129 | + .setCancelText("cancel") |
| 130 | + .setTitleText("title") |
| 131 | + .setSubCalSize(18) |
| 132 | + .setTitleSize(20) |
| 133 | + .setTitleColor(Color.BLACK) |
| 134 | + .setSubmitColor(Color.BLUE) |
| 135 | + .setCancelColor(Color.BLUE) |
| 136 | + .setTitleBgColor(0xFF666666)//Night mode |
| 137 | + .setBgColor(0xFF444444)//Night mode |
| 138 | + .setContentTextSize(18) |
| 139 | + .setLinkage(false) |
| 140 | + .setLabels("province", "city", "district") |
| 141 | + .setCyclic(false, false, false) |
| 142 | + .setSelectOptions(0, 0, 0) //default options |
| 143 | + .setOutSideCancelable(false)//dismiss, default is true |
| 144 | + .build(); |
| 145 | + |
| 146 | + pvOptions.setPicker(options1Items, options2Items, options3Items); |
| 147 | +``` |
| 148 | +## Customize Layout: |
| 149 | +```java |
| 150 | + private void initCustomTimePicker() { |
| 151 | + // be careful:In the custom layout, the layout of the ID for optionspicker |
| 152 | + // or TimePicker and its child widget must not be modified, |
| 153 | + // otherwise will be reported NullPointerException |
| 154 | + // For more details, Please refer to the two custom layouts in demo |
| 155 | + |
| 156 | + Calendar selectedDate = Calendar.getInstance();//System current time |
| 157 | + Calendar startDate = Calendar.getInstance(); |
| 158 | + startDate.set(2013,1,23); |
| 159 | + Calendar endDate = Calendar.getInstance(); |
| 160 | + endDate.set(2019,2,28); |
| 161 | + |
| 162 | + pvCustomTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() { |
| 163 | + @Override |
| 164 | + public void onTimeSelect(Date date, View v) {//call back |
| 165 | + btn_CustomTime.setText(getTime(date)); |
| 166 | + } |
| 167 | + }) .setType(TimePickerView.Type.YEAR_MONTH_DAY) |
| 168 | + .setDate(selectedDate) |
| 169 | + .setRangDate(startDate,endDate) |
| 170 | + .setLayoutRes(R.layout.pickerview_custom_time, new CustomListener() { |
| 171 | + |
| 172 | + @Override |
| 173 | + public void customLayout(View v) { |
| 174 | + final TextView tvSubmit = (TextView) v.findViewById(R.id.tv_finish); |
| 175 | + ImageView ivCancel = (ImageView) v.findViewById(R.id.iv_cancel); |
| 176 | + tvSubmit.setOnClickListener(new View.OnClickListener() { |
| 177 | + @Override |
| 178 | + public void onClick(View v) { |
| 179 | + pvCustomTime.returnData(tvSubmit); |
| 180 | + } |
| 181 | + }); |
| 182 | + ivCancel.setOnClickListener(new View.OnClickListener() { |
| 183 | + @Override |
| 184 | + public void onClick(View v) { |
| 185 | + pvCustomTime.dismiss(); |
| 186 | + } |
| 187 | + }); |
| 188 | + } |
| 189 | + }) |
| 190 | + .setDividerColor(Color.BLACK) |
| 191 | + .build(); |
| 192 | + } |
| 193 | +``` |
| 194 | + |
| 195 | +## If there is still doubt about you, pelase refer to the Demo code, or [New Issue](https://github.com/Bigkoo/Android-PickerView/issues) to me |
| 196 | + |
| 197 | +### [Here is demo code](https://github.com/Bigkoo/Android-PickerView/blob/master/app/src/main/java/com/bigkoo/pickerviewdemo/MainActivity.java) |
| 198 | + |
| 199 | +### [Methods-and-parameters](https://github.com/Bigkoo/Android-PickerView/wiki/Methods-and-parameters) |
| 200 | + |
| 201 | + |
| 202 | +## Thanks |
| 203 | + |
| 204 | +- [WheelView](https://github.com/venshine/WheelView) |
| 205 | +- [androidWheelView](https://github.com/weidongjian/androidWheelView/) |
| 206 | + |
| 207 | +#License |
| 208 | + |
| 209 | +``` |
| 210 | +Copyright 2014 Bigkoo |
| 211 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 212 | +you may not use this file except in compliance with the License. |
| 213 | +You may obtain a copy of the License at |
| 214 | +
|
| 215 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 216 | +
|
| 217 | +Unless required by applicable law or agreed to in writing, software |
| 218 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 219 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 220 | +See the License for the specific language governing permissions and |
| 221 | +limitations under the License. |
| 222 | +``` |
0 commit comments