AUDatePicker 是一个日期选择控件,本质是一个弹窗。
效果图
接口说明
/**
* Instantiates a new Date picker.
*
* @param activity the activity
* @param mode the mode
* @see #YEAR_MONTH_DAY #YEAR_MONTH_DAY#YEAR_MONTH_DAY
* @see #YEAR_MONTH #YEAR_MONTH#YEAR_MONTH
* @see #MONTH_DAY #MONTH_DAY#MONTH_DAY
*/
public AUDatePicker(Activity activity, @Mode int mode)
/**
* 设置日期范围
*
* @param startYear the start year
* @param endYear the end year
*/
public void setRange(int startYear, int endYear)
··/**
* 选中指定的年月日
*
* @param year the year
* @param month the month
* @param day the day
*/
public void setSelectedItem(int year, int month, int day)
/**
* 选中指定的日期
*
* @param yearOrMonth the year or month
* @param monthOrDay the month or day
*/
public void setSelectedItem(int yearOrMonth, int monthOrDay)
/**
* 设置日期选中的监听
*
* @param listener the listener
*/
public void setOnDatePickListener(OnDatePickListener listener) {
this.onDatePickListener = listener;
}
/**
* The interface on year month day pick listener.
*/
public interface OnYearMonthDayPickListener extends OnDatePickListener {
/**
* On date picked.
*
* @param year the year
* @param month the month
* @param day the day
*/
void onDatePicked(String year, String month, String day);
}
/**
* The interface On year month pick listener.
*/
public interface OnYearMonthPickListener extends OnDatePickListener {
/**
* On date picked.
*
* @param year the year
* @param month the month
*/
void onDatePicked(String year, String month);
}
/**
* The interface On month day pick listener.
*/
public interface OnMonthDayPickListener extends OnDatePickListener {
/**
* On date picked.
*
* @param month the month
* @param day the day
*/
void onDatePicked(String month, String day);
}
自定义属性
无自定义属性,不支持 XML 布局文件。
代码示例
AUDatePicker datePicker = new AUDatePicker(DatePickActivity.this,AUDatePicker.YEAR_MONTH_DAY);
datePicker.setRange(1949,2050);
datePicker.setOnDatePickListener(new AUDatePicker.OnYearMonthDayPickListener() {
@Override
public void onDatePicked(String year, String month, String day) {
Toast.makeText(DatePickActivity.this,year + "-" + month + "-" + day,Toast.LENGTH_LONG).show();
}
});
datePicker.show();
内嵌页面的 AUDatePicker 的使用:
AUDatePicker picker = new AUDatePicker(this);
picker.show();
picker.dismiss();
View view = picker.getOutterView();
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
layout.removeAllViews();
if(view != null) {
((ViewGroup) view.getParent()).removeAllViews();
layout.addView(view);
}
如有疑问,请搜索群号 41708565 加入钉钉群联系技术支持人员获取帮助。
文档内容是否对您有帮助?