Skip to content

Commit

Permalink
添加年月时间回调接口
Browse files Browse the repository at this point in the history
  • Loading branch information
loonggg committed May 17, 2017
1 parent 3c3c9db commit ca53c95
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,12 @@ public void onDateClick(String time) {
}
});

weekCalendar.setOnCurrentMonthDateListener(new WeekCalendar.OnCurrentMonthDateListener() {
@Override
public void onCallbackMonthDate(String year, String month) {
Toast.makeText(MainActivity.this, year + "-" + month, Toast.LENGTH_SHORT).show();
}
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class WeekCalendar extends LinearLayout {
private float daysTextSize, weekTextSize;
private Drawable daysSelectedBackground, nextArrowBg, preArrowBg, cornerMarkBg;
private List<String> selectDateList = null;
private OnCurrentMonthDateListener onCurrentMonthDateListener;

public WeekCalendar(Context context) {
super(context);
Expand Down Expand Up @@ -126,6 +127,9 @@ private void initDatas() {
private void getWholeMonthDatas(CalendarData data) {
calendarDatas = WeekCalendarUtil.getWholeMonthDay(data);//获取某天所在的整个月的数据(包含用于显示的上个月的天数和下个月的天数)
weeks = WeekCalendarUtil.getWholeWeeks(calendarDatas);//获取当月有几个星期,以及每一星期对应的数据星期数据
if (onCurrentMonthDateListener != null) {
onCurrentMonthDateListener.onCallbackMonthDate(String.valueOf(data.year), String.valueOf(data.month));
}
mTvYearMouth.setText(String.format("%s年%s月", String.valueOf(data.year), String.valueOf(data.month)));
}

Expand Down Expand Up @@ -386,6 +390,22 @@ public interface OnDateClickListener {
void onDateClick(String time);
}

/**
* 回调当前显示的年月
*/
public interface OnCurrentMonthDateListener {
void onCallbackMonthDate(String year, String month);
}

/**
* 设置显示当前月份的回调接口方法
*
* @param onCurrentMonthDateListener
*/
public void setOnCurrentMonthDateListener(OnCurrentMonthDateListener onCurrentMonthDateListener) {
this.onCurrentMonthDateListener = onCurrentMonthDateListener;
}

/**
* 设置回调接口
*/
Expand Down

0 comments on commit ca53c95

Please sign in to comment.