通过打印台发布招聘前端信息举例知乎

laravel项目常用的命令

  返回  

时间选择器

2021/8/20 14:51:33 浏览:

导入依赖

//地址选择
implementation 'com.contrarywind:Android-PickerView:4.1.6'
implementation 'com.contrarywind:wheelview:4.0.9'

创建工具类

public class Picker {
    public static void showDatePicker(Context context, final DatePickerDialog.OnDateSetListener listener) {
        showDatePicker(context, getyMCurrentTime(), listener);
    }

    public static void showDatePicker(Context context, String date, final DatePickerDialog.OnDateSetListener listener) {
        final Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
        try {
            Date parse = format.parse(date);
            calendar.setTime(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        new TimePickerBuilder(context, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                calendar.setTime(date);
                int yy = calendar.get(Calendar.YEAR);
                int mm = calendar.get(Calendar.MONTH);
                int dd = calendar.get(Calendar.DAY_OF_MONTH);
                listener.onDateSet(null, yy, mm, dd);
            }
        })

                .setType(new boolean[]{true, true, false, false, false, false})
                .setCancelText("取消")
                .setSubmitText("确定")
                .setDate(calendar)
                .isDialog(false)
                .build()
                .show();
    }

    public static void showYMDPicker(Context context, String title, String date, final DatePickerDialog.OnDateSetListener listener) {
        final Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date parse = format.parse(date);
            calendar.setTime(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        new TimePickerBuilder(context, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                calendar.setTime(date);
                int yy = calendar.get(Calendar.YEAR);
                int mm = calendar.get(Calendar.MONTH);
                int dd = calendar.get(Calendar.DAY_OF_MONTH);
                listener.onDateSet(null, yy, mm, dd);
            }
        })

                .setType(new boolean[]{true, true, true, false, false, false})
                .setCancelText("取消")
                .setSubmitText("确定")
                .setDate(calendar)
                .setTitleText("生日选择")
                .isDialog(false)
                .build()
                .show();
    }

    public interface OnOnePickerChecked<T> {
        void onChecked(T t, int i);
    }

    public static <T> void showOnePicker(Context context, String title, final List<T> data, int checkd, final OnOnePickerChecked<T> lis) {
        if (data == null || data.size() == 0)
            return;
        OptionsPickerView<T> build = new OptionsPickerBuilder(context, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                if (lis != null)
                    lis.onChecked(data.get(options1), options1);
            }
        })
                .setCancelText("取消")
                .setSubmitText("确定")
                .isDialog(false)
                .setTitleText(title)
                .setSelectOptions(checkd)
                .build();
        build.setPicker(data);
        build.show();


    }


    /**
     * 获取当前时间 yyyyMM
     *
     * @return
     */
    @SuppressLint("SimpleDateFormat")
    public static String getyMCurrentTime() {
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM");
        return s.format(new Date());
    }


}

activity调用

 Picker.showDatePicker(MineBillActivity.this, new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { // 年月日
                        mYear = year;
                        mMmonth = month+1;
                        select_date.setText(mYear + "-" + mMmonth);
                    }
                });

联系我们

如果您对我们的服务有兴趣,请及时和我们联系!

服务热线:18288888888
座机:18288888888
传真:
邮箱:888888@qq.com
地址:郑州市文化路红专路93号