大佬教程收集整理的这篇文章主要介绍了Andorid 日历控件库,可左右滑动,显示公历,农历,节假日等功能,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_301_1@封面图:
@H_301_1@源码目录结构
Features
@H_301_1@使用步骤
Gradle Dependency
Add the library to your project build.gradle
compile 'com.joybar.calendar:librarycalendar:1.0.4'
@H_301_1@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(listTo@R_618_10495@ng(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(listTo@R_618_10495@ng(mListDatE)); } @Override public void OnPageChange(int year,int month) { tv_date.setText(year + "-" + month); mListDate.clear(); } private static @R_618_10495@ng listTo@R_618_10495@ng(List<CalendarDate> list) { @R_618_10495@ngBuffer @R_618_10495@ngBuffer = new StringBuffer(); for (CalendarDate date : list) { @R_618_10495@ngBuffer.append(date.getSolar().solarYear + "-" + date.getSolar().solarMonth + "-" + date.getSolar().solarDay).append(" "); } return @R_618_10495@ngBuffer.to@R_618_10495@ng(); } }
单选或者多选的实现代码
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 日历控件库,可左右滑动,显示公历,农历,节假日等功能所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。