├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── bigkoo │ │ └── pickerviewdemo │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── bigkoo │ │ └── pickerviewdemo │ │ ├── DataModel.java │ │ ├── Util.java │ │ ├── activity │ │ ├── MainActivity.java │ │ └── TestActivity.java │ │ └── bean │ │ ├── ProvinceBean.java │ │ └── TypeBean.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── layout │ ├── activity_main.xml │ ├── activity_test.xml │ ├── activity_wheelview_test.xml │ └── layout_bottom_wheel_option.xml │ ├── menu │ └── menu_main.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pickerview ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── lvfq │ │ └── pickerview │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── lvfq │ │ └── pickerview │ │ ├── OptionsPickerView.java │ │ ├── TimePickerView.java │ │ ├── adapter │ │ ├── ArrayWheelAdapter.java │ │ ├── NumericWheelAdapter.java │ │ └── WheelAdapter.java │ │ ├── lib │ │ ├── InertiaTimerTask.java │ │ ├── LoopViewGestureListener.java │ │ ├── MessageHandler.java │ │ ├── OnItemSelectedRunnable.java │ │ ├── SmoothScrollTimerTask.java │ │ └── WheelView.java │ │ ├── listener │ │ ├── OnDismissListener.java │ │ └── OnItemSelectedListener.java │ │ ├── utils │ │ └── PickerViewAnimateUtil.java │ │ └── view │ │ ├── BasePickerView.java │ │ ├── WheelOptions.java │ │ └── WheelTime.java │ └── res │ ├── anim │ ├── slide_in_bottom.xml │ └── slide_out_bottom.xml │ ├── drawable │ └── selector_pickerview_btn.xml │ ├── layout │ ├── include_pickerview_topbar.xml │ ├── layout_basepickerview.xml │ ├── pickerview_options.xml │ └── pickerview_time.xml │ └── values │ ├── attrs.xml │ ├── bools.xml │ ├── colors.xml │ ├── dimens.xml │ ├── integers.xml │ └── strings.xml ├── preview ├── pickerdemo.gif ├── pickerdemo1x.gif ├── pickerdemo_zhangshangshenghuo.gif └── update_picker_demo.gif └── settings.gradle /.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 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 源码来自于:https://github.com/saiwu-bigkoo/Android-PickerView 2 | 3 | 站着巨人的肩膀上,做了一些调整 , 调整后效果图 4 | 5 | ![image](https://github.com/lvfaqiang/Android-PickerView-master/blob/develop/preview/update_picker_demo.gif) 6 | 7 | 博客地址:http://blog.csdn.net/lv_fq/article/details/52338513 8 | 9 | Demo 下载之后把 pickerview 作为 Module 引入到项目中, 10 | 11 | 添加工具类: 12 | ``` 13 | public class Util { 14 | 15 | /** 16 | * 时间选择回调 17 | */ 18 | public interface TimerPickerCallBack { 19 | void onTimeSelect(String date); 20 | } 21 | 22 | /** 23 | * 弹出时间选择 24 | * 25 | * @param context 26 | * @param type TimerPickerView 中定义的 选择时间类型 27 | * @param format 时间格式化 28 | * @param callBack 时间选择回调 29 | */ 30 | public static void alertTimerPicker(Context context, TimePickerView.Type type, final String format, final TimerPickerCallBack callBack) { 31 | TimePickerView pvTime = new TimePickerView(context, type); 32 | //控制时间范围 33 | // Calendar calendar = Calendar.getInstance(); 34 | // pvTime.setRange(calendar.get(Calendar.YEAR) - 20, calendar.get(Calendar.YEAR)); 35 | pvTime.setTime(new Date()); 36 | pvTime.setCyclic(false); 37 | pvTime.setCancelable(true); 38 | //时间选择后回调 39 | pvTime.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() { 40 | 41 | @Override 42 | public void onTimeSelect(Date date) { 43 | // tvTime.setText(getTime(date)); 44 | SimpleDateFormat sdf = new SimpleDateFormat(format); 45 | callBack.onTimeSelect(sdf.format(date)); 46 | } 47 | }); 48 | pvTime.setTextSize(16); 49 | //弹出时间选择器 50 | pvTime.show(); 51 | } 52 | 53 | 54 | /** 55 | * 底部滚轮点击事件回调 56 | */ 57 | public interface OnWheelViewClick { 58 | void onClick(View view, int postion); 59 | } 60 | 61 | /** 62 | * 弹出底部滚轮选择 63 | * 64 | * @param context 65 | * @param list 66 | * @param click 67 | */ 68 | public static void alertBottomWheelOption(Context context, ArrayList list, final OnWheelViewClick click) { 69 | 70 | final PopupWindow popupWindow = new PopupWindow(); 71 | 72 | View view = LayoutInflater.from(context).inflate(R.layout.layout_bottom_wheel_option, null); 73 | TextView tv_confirm = (TextView) view.findViewById(R.id.btnSubmit); 74 | final WheelView wv_option = (WheelView) view.findViewById(R.id.wv_option); 75 | wv_option.setAdapter(new ArrayWheelAdapter(list)); 76 | wv_option.setCyclic(false); 77 | wv_option.setTextSize(16); 78 | tv_confirm.setOnClickListener(new View.OnClickListener() { 79 | @Override 80 | public void onClick(View view) { 81 | popupWindow.dismiss(); 82 | click.onClick(view, wv_option.getCurrentItem()); 83 | } 84 | }); 85 | 86 | view.findViewById(R.id.btnCancel).setOnClickListener(new View.OnClickListener() { 87 | @Override 88 | public void onClick(View view) { 89 | // TODO: 2016/8/11 0011 取消 90 | popupWindow.dismiss(); 91 | } 92 | }); 93 | view.setOnTouchListener(new View.OnTouchListener() { 94 | @Override 95 | public boolean onTouch(View view, MotionEvent motionEvent) { 96 | int top = view.findViewById(R.id.ll_container).getTop(); 97 | if (motionEvent.getAction() == MotionEvent.ACTION_UP) { 98 | int y = (int) motionEvent.getY(); 99 | if (y < top) { 100 | popupWindow.dismiss(); 101 | } 102 | } 103 | return true; 104 | } 105 | }); 106 | popupWindow.setContentView(view); 107 | popupWindow.setOutsideTouchable(true); 108 | popupWindow.setFocusable(true); 109 | popupWindow.setBackgroundDrawable(new BitmapDrawable()); 110 | popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); 111 | popupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT); 112 | popupWindow.showAtLocation(((ViewGroup) ((Activity) context).findViewById(android.R.id.content)).getChildAt(0), Gravity.CENTER, 0, 0); 113 | } 114 | ``` 115 | 具体调用方法请参考 Demo。 116 | 117 | 此外,后面把该项目中的 底部弹出效果做了一下整理,详情参考 http://blog.csdn.net/lv_fq/article/details/53154026 118 | 119 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | } -------------------------------------------------------------------------------- /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/DataModel.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.pickerviewdemo; 2 | 3 | import com.bigkoo.pickerviewdemo.bean.ProvinceBean; 4 | 5 | import java.util.ArrayList; 6 | 7 | /** 8 | * -------------------------------------------- 9 | * auther : Lvfq 10 | * 2016/8/27 16:01 11 | * description : 12 | * ------------------------------------------- 13 | **/ 14 | public class DataModel { 15 | 16 | /** 17 | * 初始化三个选项卡数据。 18 | * 19 | * @param options1Items 20 | * @param options2Items 21 | * @param options3Items 22 | */ 23 | public static void initData(ArrayList options1Items, ArrayList> options2Items, ArrayList>> options3Items) { 24 | 25 | //选项1 26 | options1Items.add(new ProvinceBean(0, "广东", "广东省,以岭南东道、广南东路得名", "其他数据")); 27 | options1Items.add(new ProvinceBean(1, "湖南", "湖南省地处中国中部、长江中游,因大部分区域处于洞庭湖以南而得名湖南", "芒果TV")); 28 | options1Items.add(new ProvinceBean(3, "广西", "嗯~~", "")); 29 | 30 | //选项2 31 | ArrayList options2Items_01 = new ArrayList(); 32 | options2Items_01.add("广州"); 33 | options2Items_01.add("佛山"); 34 | options2Items_01.add("东莞"); 35 | options2Items_01.add("阳江"); 36 | options2Items_01.add("珠海"); 37 | ArrayList options2Items_02 = new ArrayList(); 38 | options2Items_02.add("长沙"); 39 | options2Items_02.add("岳阳"); 40 | ArrayList options2Items_03 = new ArrayList(); 41 | options2Items_03.add("桂林"); 42 | options2Items.add(options2Items_01); 43 | options2Items.add(options2Items_02); 44 | options2Items.add(options2Items_03); 45 | 46 | //选项3 47 | ArrayList> options3Items_01 = new ArrayList>(); 48 | ArrayList> options3Items_02 = new ArrayList>(); 49 | ArrayList> options3Items_03 = new ArrayList>(); 50 | ArrayList options3Items_01_01 = new ArrayList(); 51 | options3Items_01_01.add("白云"); 52 | options3Items_01_01.add("天河"); 53 | options3Items_01_01.add("海珠"); 54 | options3Items_01_01.add("越秀"); 55 | options3Items_01.add(options3Items_01_01); 56 | ArrayList options3Items_01_02 = new ArrayList(); 57 | options3Items_01_02.add("南海"); 58 | options3Items_01_02.add("高明"); 59 | options3Items_01_02.add("顺德"); 60 | options3Items_01_02.add("禅城"); 61 | options3Items_01.add(options3Items_01_02); 62 | ArrayList options3Items_01_03 = new ArrayList(); 63 | options3Items_01_03.add("其他"); 64 | options3Items_01_03.add("常平"); 65 | options3Items_01_03.add("虎门"); 66 | options3Items_01.add(options3Items_01_03); 67 | ArrayList options3Items_01_04 = new ArrayList(); 68 | options3Items_01_04.add("其他1"); 69 | options3Items_01_04.add("其他2"); 70 | options3Items_01_04.add("其他3"); 71 | options3Items_01.add(options3Items_01_04); 72 | ArrayList options3Items_01_05 = new ArrayList(); 73 | options3Items_01_05.add("其他1"); 74 | options3Items_01_05.add("其他2"); 75 | options3Items_01_05.add("其他3"); 76 | options3Items_01.add(options3Items_01_05); 77 | 78 | ArrayList options3Items_02_01 = new ArrayList(); 79 | options3Items_02_01.add("长沙长沙长沙长沙长沙长沙长沙长沙长沙1111111111"); 80 | options3Items_02_01.add("长沙2"); 81 | options3Items_02_01.add("长沙3"); 82 | options3Items_02_01.add("长沙4"); 83 | options3Items_02_01.add("长沙5"); 84 | options3Items_02_01.add("长沙6"); 85 | options3Items_02_01.add("长沙7"); 86 | options3Items_02_01.add("长沙8"); 87 | options3Items_02.add(options3Items_02_01); 88 | ArrayList options3Items_02_02 = new ArrayList(); 89 | options3Items_02_02.add("岳1"); 90 | options3Items_02_02.add("岳2"); 91 | options3Items_02_02.add("岳3"); 92 | options3Items_02_02.add("岳4"); 93 | options3Items_02_02.add("岳5"); 94 | options3Items_02_02.add("岳6"); 95 | options3Items_02_02.add("岳7"); 96 | options3Items_02_02.add("岳8"); 97 | options3Items_02_02.add("岳9"); 98 | options3Items_02.add(options3Items_02_02); 99 | ArrayList options3Items_03_01 = new ArrayList(); 100 | options3Items_03_01.add("好山水"); 101 | options3Items_03.add(options3Items_03_01); 102 | 103 | options3Items.add(options3Items_01); 104 | options3Items.add(options3Items_02); 105 | options3Items.add(options3Items_03); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigkoo/pickerviewdemo/Util.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.pickerviewdemo; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.graphics.drawable.BitmapDrawable; 6 | import android.view.Gravity; 7 | import android.view.LayoutInflater; 8 | import android.view.MotionEvent; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.PopupWindow; 12 | import android.widget.TextView; 13 | 14 | import com.lvfq.pickerview.TimePickerView; 15 | import com.lvfq.pickerview.adapter.ArrayWheelAdapter; 16 | import com.lvfq.pickerview.lib.WheelView; 17 | 18 | import java.text.SimpleDateFormat; 19 | import java.util.ArrayList; 20 | import java.util.Date; 21 | 22 | /** 23 | * -------------------------------------------- 24 | * Create By : Lvfq 25 | * Date : 2016/8/25 0025 下午 5:50 26 | * ------------------------------------------- 27 | **/ 28 | public class Util { 29 | 30 | /** 31 | * 时间选择回调 32 | */ 33 | public interface TimerPickerCallBack { 34 | void onTimeSelect(String date); 35 | } 36 | 37 | /** 38 | * 弹出时间选择 39 | * 40 | * @param context 41 | * @param type TimerPickerView 中定义的 选择时间类型 42 | * @param format 时间格式化 43 | * @param callBack 时间选择回调 44 | */ 45 | public static void alertTimerPicker(Context context, TimePickerView.Type type, final String format, final TimerPickerCallBack callBack) { 46 | TimePickerView pvTime = new TimePickerView(context, type); 47 | //控制时间范围 48 | // Calendar calendar = Calendar.getInstance(); 49 | // pvTime.setRange(calendar.get(Calendar.YEAR) - 20, calendar.get(Calendar.YEAR)); 50 | pvTime.setTime(new Date()); 51 | pvTime.setCyclic(false); 52 | pvTime.setCancelable(true); 53 | //时间选择后回调 54 | pvTime.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() { 55 | 56 | @Override 57 | public void onTimeSelect(Date date) { 58 | // tvTime.setText(getTime(date)); 59 | SimpleDateFormat sdf = new SimpleDateFormat(format); 60 | callBack.onTimeSelect(sdf.format(date)); 61 | } 62 | }); 63 | pvTime.setTextSize(16); 64 | //弹出时间选择器 65 | pvTime.show(); 66 | } 67 | 68 | 69 | /** 70 | * 底部滚轮点击事件回调 71 | */ 72 | public interface OnWheelViewClick { 73 | void onClick(View view, int postion); 74 | } 75 | 76 | /** 77 | * 弹出底部滚轮选择 78 | * 79 | * @param context 80 | * @param list 81 | * @param click 82 | */ 83 | public static void alertBottomWheelOption(Context context, ArrayList list, final OnWheelViewClick click) { 84 | 85 | final PopupWindow popupWindow = new PopupWindow(); 86 | 87 | View view = LayoutInflater.from(context).inflate(R.layout.layout_bottom_wheel_option, null); 88 | TextView tv_confirm = (TextView) view.findViewById(R.id.btnSubmit); 89 | final WheelView wv_option = (WheelView) view.findViewById(R.id.wv_option); 90 | wv_option.setAdapter(new ArrayWheelAdapter(list)); 91 | wv_option.setCyclic(false); 92 | wv_option.setTextSize(16); 93 | tv_confirm.setOnClickListener(new View.OnClickListener() { 94 | @Override 95 | public void onClick(View view) { 96 | popupWindow.dismiss(); 97 | click.onClick(view, wv_option.getCurrentItem()); 98 | } 99 | }); 100 | 101 | view.findViewById(R.id.btnCancel).setOnClickListener(new View.OnClickListener() { 102 | @Override 103 | public void onClick(View view) { 104 | // TODO: 2016/8/11 0011 取消 105 | popupWindow.dismiss(); 106 | } 107 | }); 108 | view.setOnTouchListener(new View.OnTouchListener() { 109 | @Override 110 | public boolean onTouch(View view, MotionEvent motionEvent) { 111 | int top = view.findViewById(R.id.ll_container).getTop(); 112 | if (motionEvent.getAction() == MotionEvent.ACTION_UP) { 113 | int y = (int) motionEvent.getY(); 114 | if (y < top) { 115 | popupWindow.dismiss(); 116 | } 117 | } 118 | return true; 119 | } 120 | }); 121 | popupWindow.setContentView(view); 122 | popupWindow.setOutsideTouchable(true); 123 | popupWindow.setFocusable(true); 124 | popupWindow.setBackgroundDrawable(new BitmapDrawable()); 125 | popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); 126 | popupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT); 127 | popupWindow.showAtLocation(((ViewGroup) ((Activity) context).findViewById(android.R.id.content)).getChildAt(0), Gravity.CENTER, 0, 0); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigkoo/pickerviewdemo/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.pickerviewdemo.activity; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.TextView; 8 | import android.widget.Toast; 9 | 10 | import com.bigkoo.pickerviewdemo.DataModel; 11 | import com.bigkoo.pickerviewdemo.R; 12 | import com.bigkoo.pickerviewdemo.Util; 13 | import com.bigkoo.pickerviewdemo.bean.ProvinceBean; 14 | import com.bigkoo.pickerviewdemo.bean.TypeBean; 15 | import com.lvfq.pickerview.OptionsPickerView; 16 | 17 | import java.util.ArrayList; 18 | 19 | 20 | public class MainActivity extends Activity { 21 | 22 | private ArrayList options1Items = new ArrayList(); 23 | private ArrayList> options2Items = new ArrayList>(); 24 | private ArrayList>> options3Items = new ArrayList>>(); 25 | 26 | private ArrayList mList = new ArrayList(); 27 | private TextView tvTime, tvOptions; 28 | private TextView tv_single_option; 29 | 30 | OptionsPickerView pvOptions; 31 | View vMasker; 32 | 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_main); 38 | 39 | vMasker = findViewById(R.id.vMasker); 40 | tvTime = (TextView) findViewById(R.id.tvTime); 41 | tvOptions = (TextView) findViewById(R.id.tvOptions); 42 | tv_single_option = (TextView) findViewById(R.id.tv_single_option); 43 | 44 | // 时间选择 45 | tvTime.setOnClickListener(new View.OnClickListener() { 46 | 47 | @Override 48 | public void onClick(View v) { 49 | Intent intent = new Intent(MainActivity.this, TestActivity.class); 50 | startActivity(intent); 51 | } 52 | }); 53 | 54 | // 单项选择 55 | for (int i = 0; i <= 10; i++) { 56 | mList.add(new TypeBean(i, "item" + i)); 57 | } 58 | 59 | tv_single_option.setOnClickListener(new View.OnClickListener() { 60 | @Override 61 | public void onClick(View v) { 62 | Util.alertBottomWheelOption(MainActivity.this, mList, new Util.OnWheelViewClick() { 63 | @Override 64 | public void onClick(View view, int postion) { 65 | Toast.makeText(MainActivity.this, mList.get(postion).getName(), Toast.LENGTH_SHORT).show(); 66 | } 67 | }); 68 | } 69 | }); 70 | 71 | 72 | showOptions(); 73 | } 74 | 75 | private void showOptions() { 76 | //选项选择器 77 | pvOptions = new OptionsPickerView(this); 78 | // 初始化三个列表数据 79 | DataModel.initData(options1Items, options2Items, options3Items); 80 | 81 | //三级联动效果 82 | pvOptions.setPicker(options1Items, options2Items, options3Items, true); 83 | //设置选择的三级单位 84 | // pwOptions.setLabels("省", "市", "区"); 85 | pvOptions.setTitle("选择城市"); 86 | pvOptions.setCyclic(false, false, false); 87 | //设置默认选中的三级项目 88 | //监听确定选择按钮 89 | pvOptions.setSelectOptions(1, 1, 1); 90 | pvOptions.setTextSize(18); 91 | pvOptions.setOnoptionsSelectListener(new OptionsPickerView.OnOptionsSelectListener() { 92 | 93 | @Override 94 | public void onOptionsSelect(int options1, int option2, int options3) { 95 | //返回的分别是三个级别的选中位置 96 | String tx = options1Items.get(options1).getPickerViewText() 97 | + options2Items.get(options1).get(option2) 98 | + options3Items.get(options1).get(option2).get(options3); 99 | tvOptions.setText(tx); 100 | vMasker.setVisibility(View.GONE); 101 | } 102 | }); 103 | //点击弹出选项选择器 104 | tvOptions.setOnClickListener(new View.OnClickListener() { 105 | 106 | @Override 107 | public void onClick(View v) { 108 | pvOptions.show(); 109 | } 110 | }); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /app/src/main/java/com/bigkoo/pickerviewdemo/activity/TestActivity.java: -------------------------------------------------------------------------------- 1 | package com.bigkoo.pickerviewdemo.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.FragmentActivity; 6 | import android.view.View; 7 | import android.widget.Toast; 8 | 9 | import com.bigkoo.pickerviewdemo.R; 10 | import com.bigkoo.pickerviewdemo.Util; 11 | import com.lvfq.pickerview.TimePickerView; 12 | 13 | /** 14 | * -------------------------------------------- 15 | * Create By : Lvfq 16 | * Date : 2016/8/25 0025 下午 5:36 17 | * ------------------------------------------- 18 | **/ 19 | public class TestActivity extends FragmentActivity implements View.OnClickListener { 20 | 21 | @Override 22 | protected void onCreate(@Nullable Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | 25 | setContentView(R.layout.activity_test); 26 | 27 | findViewById(R.id.btn_ymdhm).setOnClickListener(this); 28 | findViewById(R.id.btn_ymdh).setOnClickListener(this); 29 | findViewById(R.id.btn_ymd).setOnClickListener(this); 30 | findViewById(R.id.btn_mdhm).setOnClickListener(this); 31 | findViewById(R.id.btn_hm).setOnClickListener(this); 32 | findViewById(R.id.btn_ym).setOnClickListener(this); 33 | 34 | } 35 | 36 | @Override 37 | public void onClick(View v) { 38 | String format = ""; 39 | TimePickerView.Type type = null; 40 | switch (v.getId()) { 41 | case R.id.btn_ymdhm: 42 | type = TimePickerView.Type.ALL; 43 | format = "yyyy-MM-dd HH:mm"; 44 | break; 45 | case R.id.btn_ymdh: 46 | type = TimePickerView.Type.YEAR_MONTH_DAY_HOUR; 47 | format = "yyyy-MM-dd HH"; 48 | break; 49 | case R.id.btn_ymd: 50 | type = TimePickerView.Type.YEAR_MONTH_DAY; 51 | format = "yyyy-MM-dd"; 52 | break; 53 | case R.id.btn_mdhm: 54 | type = TimePickerView.Type.MONTH_DAY_HOUR_MIN; 55 | format = "MM-dd HH:mm"; 56 | break; 57 | case R.id.btn_hm: 58 | type = TimePickerView.Type.HOURS_MINS; 59 | format = "HH:mm"; 60 | break; 61 | case R.id.btn_ym: 62 | type = TimePickerView.Type.YEAR_MONTH; 63 | format = "yyyy-MM"; 64 | break; 65 | } 66 | Util.alertTimerPicker(this, type, format, new Util.TimerPickerCallBack() { 67 | @Override 68 | public void onTimeSelect(String date) { 69 | Toast.makeText(TestActivity.this, date, Toast.LENGTH_SHORT).show(); 70 | } 71 | }); 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lvfaqiang/Android-PickerView-master/52ebf7b683c32ff09585250388142ba946995c56/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/52ebf7b683c32ff09585250388142ba946995c56/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/52ebf7b683c32ff09585250388142ba946995c56/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/52ebf7b683c32ff09585250388142ba946995c56/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 21 | 22 | 31 | 32 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_test.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |