码迷,mamicode.com
首页 > 其他好文 > 详细

Andorid 之日历控件,可左右滑动,包含公历,农历,节假日等

时间:2017-02-07 10:44:49      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:string   class   clear   state   rda   nts   static   dateutil   list   

公司项目需要日历这个功能,经过查阅资料写了个demo,包含公历,农历,节假日等,还可左右滑动。

效果图:

技术分享

代码:

public class MainActivity extends AppCompatActivity implements
        CalendarViewPagerFragment.OnPageChangeListener,
        CalendarViewFragment.OnDateClickListener,
        CalendarViewFragment.OnDateCancelListener {

    private TextView tv_date;
    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 = CalendarViewPagerFragment.newInstance();
        tx.replace(R.id.fl_content, fragment);
        tx.commit();
    }

    @Override
    public void onDateClick(CalendarDate calendarDate) {

        int year = calendarDate.getSolar().solarYear;
        int month = calendarDate.getSolar().solarMonth;
        int day = calendarDate.getSolar().solarDay;
        String data;
        if (day < 10) {
            data = DateUtils.getWeekday(year + "-" + month + "-0" + day);
            tv_date.setText(year + "-" + month + "-0" + day + " " + month + "月" + "  " + data);
        } else {
            data = DateUtils.getWeekday(year + "-" + month + "-" + day);
            tv_date.setText(year + "-" + month + "-" + day + " " + month + "月" + "  " + data);
        }

    }

    @Override
    public void onDateCancel(CalendarDate calendarDate) {
    }

    @Override
    public void onPageChange(int year, int month) {
        tv_date.setText(year + "-" + month);
        mListDate.clear();
    }

}

由于代码太多,完整代码未给出,源码直接下载即可

 

源码点击下载

 

Andorid 之日历控件,可左右滑动,包含公历,农历,节假日等

标签:string   class   clear   state   rda   nts   static   dateutil   list   

原文地址:http://www.cnblogs.com/zhangqie/p/6372918.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!