PickerView 时间/城市联动选择器TimePickerBuilder+OptionsPickerBuilder

//时间选择器库
implementation 'com.contrarywind:Android-PickerView:4.1.6'

//1  时间显示

//private TimePickerView pvTime;
/**
     * 生日选择器
     */
    private void initLunarPicker() {
        Calendar selectedDate = Calendar.getInstance();//系统当前时间
        selectedDate.set(1990, 1, 1);
        Calendar startDate = Calendar.getInstance();
        startDate.set(1970, 1, 1);
        Calendar endDate = Calendar.getInstance();
        //endDate.set(2069, 2, 28);

        pvTime = new TimePickerBuilder(this, (date, v) -> {//选中事件回调
            birth = date;
            tvBirthday.setText(TimeUtils.getYMDFormat(date));
//                mApplyBlindDateBir.setText(new SimpleDateFormat("yyyy-MM-dd").format(date));
        }).setDate(selectedDate)
                .setRangDate(startDate, endDate)
                .setContentTextSize(18)
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("年", "月", "日", null, null, null)
                .setLineSpacingMultiplier(1.2f)
                .setTextXOffset(0, 0, 0, 40, 0, -40)
                .isCenterLabel(false) //是否只显示中间选中项的label文字,false则每项item全部都带有label。
                .build();
    }


 if (pvTime != null) {
                    pvTime.show();
                }

//2 条件选择

//条件选择器
 OptionsPickerView pvOptions = new OptionsPickerBuilder(MainActivity.this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3 ,View v) {
                //返回的分别是三个级别的选中位置
                String tx = options1Items.get(options1).getPickerViewText()
                        + options2Items.get(options1).get(option2)
                        + options3Items.get(options1).get(option2).get(options3).getPickerViewText();
                tvOptions.setText(tx);
            }
        }).build();
 pvOptions.setPicker(options1Items, options2Items, options3Items);
 pvNoLinkOptions.setSelectOptions(1, 1);
 pvOptions.show(); 

 

你可能感兴趣的:(三方框架)