├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── drawable-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── styles.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── strings.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ ├── menu │ │ │ │ └── menu_main.xml │ │ │ └── layout │ │ │ │ ├── activity_wheelview_test.xml │ │ │ │ ├── layout_bottom_wheel_option.xml │ │ │ │ ├── activity_main.xml │ │ │ │ └── activity_test.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── bigkoo │ │ │ └── pickerviewdemo │ │ │ ├── bean │ │ │ ├── TypeBean.java │ │ │ └── ProvinceBean.java │ │ │ ├── activity │ │ │ ├── TestActivity.java │ │ │ └── MainActivity.java │ │ │ ├── DataModel.java │ │ │ └── Util.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── bigkoo │ │ └── pickerviewdemo │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── pickerview ├── .gitignore ├── src │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── res │ │ │ ├── values │ │ │ │ ├── integers.xml │ │ │ │ ├── bools.xml │ │ │ │ ├── strings.xml │ │ │ │ ├── attrs.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── colors.xml │ │ │ ├── drawable │ │ │ │ └── selector_pickerview_btn.xml │ │ │ ├── anim │ │ │ │ ├── slide_in_bottom.xml │ │ │ │ └── slide_out_bottom.xml │ │ │ └── layout │ │ │ │ ├── layout_basepickerview.xml │ │ │ │ ├── pickerview_options.xml │ │ │ │ ├── pickerview_time.xml │ │ │ │ └── include_pickerview_topbar.xml │ │ └── java │ │ │ └── com │ │ │ └── lvfq │ │ │ └── pickerview │ │ │ ├── listener │ │ │ ├── OnItemSelectedListener.java │ │ │ └── OnDismissListener.java │ │ │ ├── lib │ │ │ ├── OnItemSelectedRunnable.java │ │ │ ├── LoopViewGestureListener.java │ │ │ ├── MessageHandler.java │ │ │ ├── SmoothScrollTimerTask.java │ │ │ ├── InertiaTimerTask.java │ │ │ └── WheelView.java │ │ │ ├── adapter │ │ │ ├── WheelAdapter.java │ │ │ ├── ArrayWheelAdapter.java │ │ │ └── NumericWheelAdapter.java │ │ │ ├── utils │ │ │ └── PickerViewAnimateUtil.java │ │ │ ├── OptionsPickerView.java │ │ │ ├── TimePickerView.java │ │ │ └── view │ │ │ ├── BasePickerView.java │ │ │ ├── WheelOptions.java │ │ │ └── WheelTime.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── lvfq │ │ └── pickerview │ │ └── ApplicationTest.java ├── build.gradle └── proguard-rules.pro ├── settings.gradle ├── preview ├── pickerdemo.gif ├── pickerdemo1x.gif ├── update_picker_demo.gif └── pickerdemo_zhangshangshenghuo.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── README.md └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /pickerview/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':pickerview' 2 | -------------------------------------------------------------------------------- /preview/pickerdemo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lvfaqiang/Android-PickerView-master/HEAD/preview/pickerdemo.gif -------------------------------------------------------------------------------- /preview/pickerdemo1x.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lvfaqiang/Android-PickerView-master/HEAD/preview/pickerdemo1x.gif -------------------------------------------------------------------------------- /preview/update_picker_demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lvfaqiang/Android-PickerView-master/HEAD/preview/update_picker_demo.gif -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lvfaqiang/Android-PickerView-master/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /preview/pickerdemo_zhangshangshenghuo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lvfaqiang/Android-PickerView-master/HEAD/preview/pickerdemo_zhangshangshenghuo.gif -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lvfaqiang/Android-PickerView-master/HEAD/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lvfaqiang/Android-PickerView-master/HEAD/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lvfaqiang/Android-PickerView-master/HEAD/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lvfaqiang/Android-PickerView-master/HEAD/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /pickerview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /pickerview/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 300 5 | -------------------------------------------------------------------------------- /pickerview/src/main/res/values/bools.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | -------------------------------------------------------------------------------- /pickerview/src/main/java/com/lvfq/pickerview/listener/OnItemSelectedListener.java: -------------------------------------------------------------------------------- 1 | package com.lvfq.pickerview.listener; 2 | 3 | 4 | public interface OnItemSelectedListener { 5 | void onItemSelected(int index); 6 | } 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /pickerview/src/main/java/com/lvfq/pickerview/listener/OnDismissListener.java: -------------------------------------------------------------------------------- 1 | package com.lvfq.pickerview.listener; 2 | 3 | /** 4 | * Created by Sai on 15/8/9. 5 | */ 6 | public interface OnDismissListener { 7 | public void onDismiss(Object o); 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PickerViewDemo 5 | Hello world! 6 | Settings 7 | 8 | 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Aug 15 16:08:28 CST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /pickerview/src/main/res/drawable/selector_pickerview_btn.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /pickerview/src/main/res/anim/slide_in_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | -------------------------------------------------------------------------------- /pickerview/src/main/res/anim/slide_out_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | -------------------------------------------------------------------------------- /pickerview/src/androidTest/java/com/lvfq/pickerview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.lvfq.pickerview; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/bigkoo/pickerviewdemo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.pickerviewdemo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /pickerview/src/main/java/com/lvfq/pickerview/lib/OnItemSelectedRunnable.java: -------------------------------------------------------------------------------- 1 | package com.lvfq.pickerview.lib; 2 | 3 | final class OnItemSelectedRunnable implements Runnable { 4 | final WheelView loopView; 5 | 6 | OnItemSelectedRunnable(WheelView loopview) { 7 | loopView = loopview; 8 | } 9 | 10 | @Override 11 | public final void run() { 12 | loopView.onItemSelectedListener.onItemSelected(loopView.getCurrentItem()); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /pickerview/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 取消 4 | 确定 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | 22 | # Android Studio 23 | .idea/ 24 | .gradle 25 | /*/local.properties 26 | /*/out 27 | build 28 | /*/*/production 29 | *.iml 30 | *.iws 31 | *.ipr 32 | *~ 33 | *.swp -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_wheelview_test.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /pickerview/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /pickerview/src/main/res/layout/layout_basepickerview.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /pickerview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | 4 | android { 5 | compileSdkVersion 21 6 | buildToolsVersion "20.0.0" 7 | 8 | defaultConfig { 9 | minSdkVersion 14 10 | targetSdkVersion 21 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | } 25 | 26 | -------------------------------------------------------------------------------- /pickerview/src/main/java/com/lvfq/pickerview/lib/LoopViewGestureListener.java: -------------------------------------------------------------------------------- 1 | package com.lvfq.pickerview.lib; 2 | 3 | import android.view.MotionEvent; 4 | 5 | final class LoopViewGestureListener extends android.view.GestureDetector.SimpleOnGestureListener { 6 | 7 | final WheelView loopView; 8 | 9 | LoopViewGestureListener(WheelView loopview) { 10 | loopView = loopview; 11 | } 12 | 13 | @Override 14 | public final boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 15 | loopView.scrollBy(velocityY); 16 | return true; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /pickerview/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 44dp 4 | 5 | 10dp 6 | 7 | 30dp 8 | 9 | 20sp 10 | 21sp 11 | 12 | 20sp 13 | 14 | -------------------------------------------------------------------------------- /pickerview/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #057dff 4 | #c2daf5 5 | #f5f5f5 6 | #000000 7 | #a8a8a8 8 | #2a2a2a 9 | #d5d5d5 10 | 11 | #60000000 12 | 13 | 14 | -------------------------------------------------------------------------------- /pickerview/src/main/java/com/lvfq/pickerview/adapter/WheelAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lvfq.pickerview.adapter; 2 | 3 | public interface WheelAdapter { 4 | /** 5 | * Gets items count 6 | * @return the count of wheel items 7 | */ 8 | public int getItemsCount(); 9 | 10 | /** 11 | * Gets a wheel item by index. 12 | * 13 | * @param index the item index 14 | * @return the wheel item text or null 15 | */ 16 | public T getItem(int index); 17 | 18 | /** 19 | * Gets maximum item length. It is used to determine the wheel width. 20 | * If -1 is returned there will be used the default wheel width. 21 | * 22 | * @return the maximum item length or -1 23 | */ 24 | public int indexOf(T o); 25 | } 26 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/Sai/Documents/software/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /pickerview/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/Sai/Documents/software/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "22.0.0" 6 | 7 | defaultConfig { 8 | applicationId "com.lvfq.pickerviewdemo" 9 | minSdkVersion 14 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | compile project(':pickerview') 25 | // compile 'com.bigkoo:pickerview:2.0.8' 26 | compile 'com.android.support:appcompat-v7:23.1.0' 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /pickerview/src/main/java/com/lvfq/pickerview/utils/PickerViewAnimateUtil.java: -------------------------------------------------------------------------------- 1 | package com.lvfq.pickerview.utils; 2 | 3 | import android.view.Gravity; 4 | 5 | import com.bigkoo.pickerview.R; 6 | 7 | /** 8 | * Created by Sai on 15/8/9. 9 | */ 10 | public class PickerViewAnimateUtil { 11 | private static final int INVALID = -1; 12 | /** 13 | * Get default animation resource when not defined by the user 14 | * 15 | * @param gravity the gravity of the dialog 16 | * @param isInAnimation determine if is in or out animation. true when is is 17 | * @return the id of the animation resource 18 | */ 19 | public static int getAnimationResource(int gravity, boolean isInAnimation) { 20 | switch (gravity) { 21 | case Gravity.BOTTOM: 22 | return isInAnimation ? R.anim.slide_in_bottom : R.anim.slide_out_bottom; 23 | } 24 | return INVALID; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigkoo/pickerviewdemo/bean/TypeBean.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.pickerviewdemo.bean; 2 | 3 | /** 4 | * -------------------------------------------- 5 | * Create By : Lvfq 6 | * Date : 2016/8/28 0028 下午 3:55 7 | * ------------------------------------------- 8 | **/ 9 | public class TypeBean { 10 | 11 | private int id; 12 | private String name; 13 | 14 | public TypeBean(int id, String name) { 15 | this.id = id; 16 | this.name = name; 17 | } 18 | 19 | public int getId() { 20 | return id; 21 | } 22 | 23 | public void setId(int id) { 24 | this.id = id; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | //这个用来显示在PickerView上面的字符串,PickerView会通过反射获取getPickerViewText方法显示出来。 36 | public String getPickerViewText() { 37 | //这里还可以判断文字超长截断再提供显示 38 | return name; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /pickerview/src/main/java/com/lvfq/pickerview/lib/MessageHandler.java: -------------------------------------------------------------------------------- 1 | package com.lvfq.pickerview.lib; 2 | 3 | import android.os.Handler; 4 | import android.os.Message; 5 | 6 | final class MessageHandler extends Handler { 7 | public static final int WHAT_INVALIDATE_LOOP_VIEW = 1000; 8 | public static final int WHAT_SMOOTH_SCROLL = 2000; 9 | public static final int WHAT_ITEM_SELECTED = 3000; 10 | 11 | final WheelView loopview; 12 | 13 | MessageHandler(WheelView loopview) { 14 | this.loopview = loopview; 15 | } 16 | 17 | @Override 18 | public final void handleMessage(Message msg) { 19 | switch (msg.what) { 20 | case WHAT_INVALIDATE_LOOP_VIEW: 21 | loopview.invalidate(); 22 | break; 23 | 24 | case WHAT_SMOOTH_SCROLL: 25 | loopview.smoothScroll(WheelView.ACTION.FLING); 26 | break; 27 | 28 | case WHAT_ITEM_SELECTED: 29 | loopview.onItemSelected(); 30 | break; 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_bottom_wheel_option.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 21 | 22 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /pickerview/src/main/java/com/lvfq/pickerview/adapter/ArrayWheelAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lvfq.pickerview.adapter; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * The simple Array wheel adapter 7 | * @param the element type 8 | */ 9 | public class ArrayWheelAdapter implements WheelAdapter { 10 | 11 | /** The default items length */ 12 | public static final int DEFAULT_LENGTH = 4; 13 | 14 | // items 15 | private ArrayList items; 16 | // length 17 | private int length; 18 | 19 | /** 20 | * Constructor 21 | * @param items the items 22 | * @param length the max items length 23 | */ 24 | public ArrayWheelAdapter(ArrayList items, int length) { 25 | this.items = items; 26 | this.length = length; 27 | } 28 | 29 | /** 30 | * Contructor 31 | * @param items the items 32 | */ 33 | public ArrayWheelAdapter(ArrayList items) { 34 | this(items, DEFAULT_LENGTH); 35 | } 36 | 37 | @Override 38 | public Object getItem(int index) { 39 | if (index >= 0 && index < items.size()) { 40 | return items.get(index); 41 | } 42 | return ""; 43 | } 44 | 45 | @Override 46 | public int getItemsCount() { 47 | return items.size(); 48 | } 49 | 50 | @Override 51 | public int indexOf(Object o){ 52 | return items.indexOf(o); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /pickerview/src/main/java/com/lvfq/pickerview/adapter/NumericWheelAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lvfq.pickerview.adapter; 2 | 3 | 4 | /** 5 | * Numeric Wheel adapter. 6 | */ 7 | public class NumericWheelAdapter implements WheelAdapter { 8 | 9 | /** The default min value */ 10 | public static final int DEFAULT_MAX_VALUE = 9; 11 | 12 | /** The default max value */ 13 | private static final int DEFAULT_MIN_VALUE = 0; 14 | 15 | // Values 16 | private int minValue; 17 | private int maxValue; 18 | 19 | /** 20 | * Default constructor 21 | */ 22 | public NumericWheelAdapter() { 23 | this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE); 24 | } 25 | 26 | /** 27 | * Constructor 28 | * @param minValue the wheel min value 29 | * @param maxValue the wheel max value 30 | */ 31 | public NumericWheelAdapter(int minValue, int maxValue) { 32 | this.minValue = minValue; 33 | this.maxValue = maxValue; 34 | } 35 | 36 | @Override 37 | public Object getItem(int index) { 38 | if (index >= 0 && index < getItemsCount()) { 39 | int value = minValue + index; 40 | return value; 41 | } 42 | return 0; 43 | } 44 | 45 | @Override 46 | public int getItemsCount() { 47 | return maxValue - minValue + 1; 48 | } 49 | 50 | @Override 51 | public int indexOf(Object o){ 52 | return (int)o - minValue; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 21 | 22 | 31 | 32 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigkoo/pickerviewdemo/bean/ProvinceBean.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.pickerviewdemo.bean; 2 | 3 | /** 4 | * Created by Sai on 15/11/22. 5 | */ 6 | public class ProvinceBean { 7 | private long id; 8 | private String name; 9 | private String description; 10 | private String others; 11 | 12 | public ProvinceBean(long id,String name,String description,String others){ 13 | this.id = id; 14 | this.name = name; 15 | this.description = description; 16 | this.others = others; 17 | } 18 | 19 | public long getId() { 20 | return id; 21 | } 22 | 23 | public void setId(long id) { 24 | this.id = id; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public String getDescription() { 36 | return description; 37 | } 38 | 39 | public void setDescription(String description) { 40 | this.description = description; 41 | } 42 | 43 | public String getOthers() { 44 | return others; 45 | } 46 | 47 | public void setOthers(String others) { 48 | this.others = others; 49 | } 50 | 51 | //这个用来显示在PickerView上面的字符串,PickerView会通过反射获取getPickerViewText方法显示出来。 52 | public String getPickerViewText() { 53 | //这里还可以判断文字超长截断再提供显示 54 | return name; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /pickerview/src/main/res/layout/pickerview_options.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 18 | 19 | 25 | 26 | 31 | 32 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_test.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |