封面图:
demo效果图
源码目录结构
Features
日历左右滑动. 显示阳历,农历,节假日和二十四节气 实现对某月日期的单选或者多选.使用步骤
Gradle Dependency
Add the library to your project build.gradle
compile 'com.joybar.calendar:librarycalendar:1.0.4'
Sample Usage
实现OnPagechangelistener和OnDateClickListener接口,如果实现多选,需要实现 OnDateCancelListener
public class MainActivity extends AppCompatActivity implements CalendarVIEwPagerFragment.OnPagechangelistener,CalendarVIEwFragment.OnDateClickListener,CalendarVIEwFragment.OnDateCancelListener { private TextVIEw tv_date; private boolean isChoiceModelSingle = false; private List<CalendarDate> mListDate = new ArrayList<>(); @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); tv_date = (TextVIEw) findVIEwByID(R.ID.tv_date); initFragment(); } private voID initFragment(){ FragmentManager fm = getSupportFragmentManager(); FragmentTransaction tx = fm.beginTransaction(); // Fragment fragment = new CalendarVIEwPagerFragment(); Fragment fragment = CalendarVIEwPagerFragment.newInstance(isChoiceModelSingle); tx.replace(R.ID.fl_content,fragment); tx.commit(); } @OverrIDe public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_im,menu); return true; } @OverrIDe public boolean onoptionsItemSelected(MenuItem item) { switch (item.getItemID()) { case R.ID.menu_single: isChoiceModelSingle = true; initFragment(); break; case R.ID.menu_multi: isChoiceModelSingle = false; initFragment(); break; default: break; } return true; } @OverrIDe public voID OnDateClick(CalendarDate calendarDate) { int year = calendarDate.getSolar().solarYear; int month = calendarDate.getSolar().solarMonth; int day = calendarDate.getSolar().solarDay; if (isChoiceModelSingle) { tv_date.setText(year + "-" + month + "-" + day); } else { //System.out.println(calendarDate.getSolar().solarDay); mListDate.add(calendarDate); tv_date.setText(ListToString(mListDate)); } } @OverrIDe public voID OnDateCancel(CalendarDate calendarDate) { int count = mListDate.size(); for (int i = 0; i < count; i++) { CalendarDate date = mListDate.get(i); if (date.getSolar().solarDay == calendarDate.getSolar().solarDay) { mListDate.remove(i); break; } } tv_date.setText(ListToString(mListDate)); } @OverrIDe public voID OnPageChange(int year,int month) { tv_date.setText(year + "-" + month); mListDate.clear(); } private static String ListToString(List<CalendarDate> List) { StringBuffer stringBuffer = new StringBuffer(); for (CalendarDate date : List) { stringBuffer.append(date.getSolar().solarYear + "-" + date.getSolar().solarMonth + "-" + date.getSolar().solarDay).append(" "); } return stringBuffer.toString(); } }
单选或者多选的实现代码
if (isChoiceModelSingle) { mGrIDVIEw.setChoiceMode(GrIDVIEw.CHOICE_MODE_SINGLE); } else { mGrIDVIEw.setChoiceMode(GrIDVIEw.CHOICE_MODE_MulTIPLE); } mGrIDVIEw.setonItemClickListener(new AdapterVIEw.OnItemClickListener() { @OverrIDe public voID onItemClick(AdapterVIEw<?> parent,VIEw vIEw,int position,long ID) { CalendarDate calendarDate = ((CalendarGrIDVIEwAdapter) mGrIDVIEw.getAdapter()).getListData().get(position); if (isChoiceModelSingle) { //单选 if (finalMListDataCalendar.get(position).isInThisMonth()) { onDateClickListener.OnDateClick(calendarDate); } else { mGrIDVIEw.setItemChecked(position,false); } } else { //多选 if (finalMListDataCalendar.get(position).isInThisMonth()) { // mGrIDVIEw.getCheckedItemIDs() if(!mGrIDVIEw.isItemChecked(position)){ onDateCancelListener.OnDateCancel(calendarDate); } else { onDateClickListener.OnDateClick(calendarDate); } } else { mGrIDVIEw.setItemChecked(position,false); } } } });
git地址:https://github.com/myjoybar/androID-calendar-vIEw
以上就是AndroID 日历控件的资料整理,后续继续补充相关资料,谢谢大家对本站的支持!
总结以上是内存溢出为你收集整理的Andorid 日历控件库,可左右滑动,显示公历,农历,节假日等功能全部内容,希望文章能够帮你解决Andorid 日历控件库,可左右滑动,显示公历,农历,节假日等功能所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)