标签:
一个自定义时间日期的控件,依赖类是GitHub下的。比较好用,现在将使用流程记下:
1.布局文件
<TextView android:id="@+id/tv_remunera_day_datepick" style="@style/input_datepicker" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginTop="10dp" android:hint="@string/choice_date" />
public class RemunerationItemByDayFragment extends Fragment { tv_datePicker.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((RemunerationActivity)getActivity()).setDatePicker(tv_datePicker, "yyyy/MM/dd"); } }); tv_datePicker.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String valTime = s.toString(); Log.i(TAG, valTime + subjectId + typeId); if (!valTime.equals("") && !subjectId.equals("") && !typeId.equals("")) { getRemunerationByDate(valTime, subjectId, typeId); } else { Toast.makeText(context, "请选择对应模块和输入日期!", Toast.LENGTH_LONG).show(); } } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void afterTextChanged(Editable arg0) { } }); }
private Builder slidDatebuild; slidDatebuild = new SlideDateTimePicker.Builder(getSupportFragmentManager()); public void setDatePicker(TextView tv, String formatstr) { slidDatebuild.setInitialDate(new Date()) .setListener(new DatePickerListener(tv, formatstr)) // .setMinDate(minDate) // .setMaxDate(maxDate) // .setIs24HourTime(true) // .setTheme(SlideDateTimePicker.HOLO_DARK) // .setIndicatorColor(Color.parseColor("#990000")) .build().show(); } private class DatePickerListener extends SlideDateTimeListener { TextView tv_date; SimpleDateFormat mFormatter; @SuppressLint("SimpleDateFormat") public DatePickerListener(TextView tv, String formatstr) { mFormatter = new SimpleDateFormat(formatstr); tv_date = tv; } @Override public void onDateTimeSet(Date date) { tv_date.setText(mFormatter.format(date)); } }
标签:
原文地址:http://my.oschina.net/u/2283209/blog/469911