SuperCalendar
==========================
簡單使用的日歷 項目鏈接
Usage
Include MonthPager
in your layout XML.
<com.ldf.calendar.view.MonthPager>
android:layout_width="match_parent"
android:layout_height="270dp"
</com.ldf.calendar.view.MonthPager>
目前來看 相比于Dialog選擇日歷 我的控件更適合于Activity/Fragment在Activity的onCreate
或者Fragment的onCreateView
你需要實現(xiàn)這兩個方法來啟動日歷并裝填進數(shù)據
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_syllabus);
initCurrentDate();
initCalendarView();
}
private void initCurrentDate() {
currentDate = new CalendarDate();
}
private void initCalendarView() {
initListener();
calendarAdapter = new CalendarViewAdapter(context , onSelectDateListener);
initMarkData();
initMonthPager();
}
使用此方法回調日歷點擊事件
private void initListener() {
onSelectDateListener = new OnSelectDateListener() {
@Override
public void onSelectDate(CalendarDate date) {
refreshClickDate(date);
}
@Override
public void onSelectOtherMonth(int offset) {
monthPager.setCurrentItem(mCurrentPage + offset);
}
};
}
使用此方法初始化日歷標記數(shù)據
private void initMarkData() {
HashMap markData = new HashMap<>();
markData.put("2017-8-9" , "1");
markData.put("2017-7-9" , "0");
markData.put("2017-6-9" , "1");
markData.put("2017-6-10" , "0");
calendarAdapter.setMarkData(markData);
}
使用此方法給MonthPager添加上相關監(jiān)聽
monthPager.addOnPageChangeListener(new MonthPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
mCurrentPage = position;
currentCalendars = calendarAdapter.getAllItems();
if(currentCalendars.get(position % currentCalendars.size()) instanceof Calendar){
//you code
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
Download
Gradle:
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://www.jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.MagicMashRoom:FuckCalendar:v1.0.1'
}