Android仿ios时间日期选择器

时间:2022-05-19 18:05:28
1.使用开源控件:
compile 'com.bigkoo:pickerview:2.1.1'
日期选择:
private void timePicke(final EditText editText) {        editText.setInputType(InputType.TYPE_NULL);        final TimePickerView pvTime = new TimePickerView(context, TimePickerView.Type.YEAR_MONTH_DAY);        pvTime.setTime(new Date());        pvTime.setCyclic(true);        pvTime.setCancelable(true);        //时间选择后回调        pvTime.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {            @Override            public void onTimeSelect(Date date) {                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");                editText.setText(format.format(date));            }        });        editText.setOnTouchListener(new View.OnTouchListener() {            @Override            public boolean onTouch(View view, MotionEvent motionEvent) {                pvTime.show();                return true;            }        });    }

自定义条目选择:
private void currentPicke(final EditText editText) {        editText.setInputType(InputType.TYPE_NULL);        final ArrayList<String> options1Items = new ArrayList<>();        options1Items.add("卖方");        options1Items.add("买方");        final OptionsPickerView pvOptions = new OptionsPickerView(context);        pvOptions.setPicker(options1Items);        pvOptions.setCyclic(false);        pvOptions.setSelectOptions(0);        pvOptions.setOnoptionsSelectListener(new OptionsPickerView.OnOptionsSelectListener() {            @Override            public void onOptionsSelect(int options1, int option2, int options3) {                String tx = options1Items.get(options1);                myRole = tx;                list.get(0).setSubTitle(tx);                editText.setText(tx);            }        });        editText.setOnTouchListener(new View.OnTouchListener() {            @Override            public boolean onTouch(View view, MotionEvent motionEvent) {                pvOptions.show();                return true;            }        });    }