分享好友 移动开发首页 频道列表

炫酷的日历和 ListView 结合的开源控件,收藏一下,说不定哪天就能用上...

Android开发  2016-09-08 08:230

CalendarListView

A custom ListView combine with CalendarView which interactive each other. just watch demo to get more detail.

Demo

Apk Download:CalendarListView.apk

Download

compile 'com.kelin.calendarlistview:library:1.0.1'

中文文档: CalendarListView 日历列表文档

Usage

1、Custom style of your CalendarView (like:add price、tag、icon into your items of CalendarView)

//create a Model extends BaseCalendarItemModel then add your custom field. 
public class CustomCalendarItemModel  extends BaseCalendarItemModel{     
   //data count.
   private int count;
   private boolean isFav;
   ...
   //getXXX 
   //setXXX
   ...
}
//create a custom Adapter extends BaseCalendarItemAdapter<T> (T  extends //BaseCalendarItemModel),then override getView function to custom your 
//calendar item's style. 
public class CalendarItemAdapter extends BaseCalendarItemAdapter<CustomCalendarItemModel>{
    //date format:"yyyy-MM-dd"
    @Override
    public View getView(String date, CustomCalendarItemModel model, View convertView, ViewGroup parent) {
        // CustomCalendarItemModel model = dayModelList.get(date); is supported.
        ....
        ....
        ViewGroup view = (ViewGroup) LayoutInflater.from(mContext).inflate(R.layout.custom_calendar_item, null);
        TextView dayNum = (TextView)  view.findViewById(R.id.day_num);
        dayNum.setText(model.getDayNumber());
        ....
        //get data from model then render your UI.
        ....
        ....
   }
}

tips:you can just use BaseCalendarItemAdapter but it is only show date in calendar View.

2、Custom style of your ListView,override getSectionHeaderView and getItemView

public class ListItemAdapter extends BaseCalendarListAdapter<ListModel> {
    //date format:'yyyy-MM-dd'
    @Override
    public View getSectionHeaderView(String date, View convertView, ViewGroup parent) {
       // List<ListModel> modelList = dateDataMap.get(date);is supported.
       .....
       //custom style of SectionHeader
       .....
    }

    @Override
    public View getItemView(ListModel model,String date, int pos, View convertView, ViewGroup parent) {
      //you can get model by follow code. 
      //List<ListModel> modelList = dateDataMap.get(date);
      //model = modelList.get(pos) 

      .....
      //custom style of List Items
      .....
   }
}

3、Initialize CalendarListView and set CalendarItemAdapter and ListItemAdapter

<com.kelin.calendarlistview.library.CalendarListView   
   android:id="@+id/calendar_listview"    
   android:layout_width="match_parent"    
   android:layout_height="match_parent">
</com.kelin.calendarlistview.library.CalendarListView>
@Override
protected void onCreate(Bundle savedInstanceState) {
 ...
 calendarListView = (CalendarListView) findViewById(R.id.calendar_listview);

 listItemAdapter = new ListItemAdapter(this);
 calendarItemAdapter = new CalendarItemAdapter(this);

 calendarListView.setCalendarListViewAdapter(calendarItemAdapter, listItemAdapter);

 ...
}

4、Loading data from server then update DataSet

  • CalendarView
private void onCalendarDataLoadFinish(List<Data> datas){
    ....
    ....
    //TreeMap<String, T>,key:'yyyy-MM-dd',value:model of this date.
    TreeMap<String, CustomCalendarItemModel> dateMap=calendarItemAdapter.getDayModelList();
    ....
    CustomCalendarItemModel customCalendarItemModel = dateMap.get(date);
    //update model
    customCalendarItemModel.setXXX(data.getXXX());
    ....
    calendarItemAdapter.notifyDataSetChanged();
}
  • ListView
//key:'yyyy-mm-dd' format date  
private TreeMap<String, List<ListModel>> listTreeMap = new TreeMap<>();

private void onListDataLoadFinish(List<Data> datas){
   ....
   ....
  forData item:datas) {
     String day=item.getDate();
    //add data
     if (listTreeMap.get(day) != null) {    
         List<NewsService.News.StoriesBean> list = listTreeMap.get(day);    
         list.add(i);
      } else {    
         List<NewsService.News.StoriesBean> list = new ArrayList<NewsService.News.StoriesBean>();    
         list.add(i);   
         listTreeMap.put(day, list);
     }
  }
 ....
 listItemAdapter.setDateDataMap(listTreeMap);
 listItemAdapter.notifyDataSetChanged();
}

5、event support

  • date selected.
calendarListView.setOnCalendarViewItemClickListener(new CalendarListView.OnCalendarViewItemClickListener() {   
     @Override    
     public void onDateSelected(View View, String selectedDate, int listSection, SelectedDateRegion selectedDateRegion) {   
     //do something....
     }
});
  • month changed.
calendarListView.setOnMonthChangedListener(new CalendarListView.OnMonthChangedListener() {    
       @Override    
       public void onMonthChanged(String yearMonth) {
       //yearMonth:'yyyy-MM-dd'

       }
});
  • refresh and load more.
calendarListView.setOnListPullListener(new CalendarListView.onListPullListener() {    
    @Override    
    public void onRefresh() {

    }    
    @Override    
    public void on
LoadMore() {

    }
});

License

Copyright 2016 Kelin Hong

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

查看更多关于【Android开发】的文章

展开全文
相关推荐
反对 0
举报 0
评论 0
图文资讯
热门推荐
优选好物
更多热点专题
更多推荐文章
android中listview的一些样式设置
在 Android中,ListView是最常用的一个控件,在做UI设计的时候,很多人希望能够改变一下它的背景,使他能够符合整体的UI设计,改变背景背很简单只需要准备一张图片然后指定属性 android:background=”@drawable/bg”,不过不要高兴地太早,当你这么做以后,发

0评论2016-10-13142

React Native填坑之旅--ListView篇
列表显示数据,基本什么应用都是必须。笔者写作的时候RN版本是0.34。今天就来从浅到深的看看React Native的ListView怎么使用。首先是使用写死的数据,之后会使用网络请求的数据在界面中显示。最后加上一个ActivityIndicator,网络请求的过程中显示Loading图标

0评论2016-10-07154

[原]判断Listview滑动到了最底部(且最后一个item完整显示)
记录下代码:listView.setOnScrollListener(new AbsListView.OnScrollListener() {@Overridepublic void onScrollStateChanged(AbsListView view, int scrollState) {}@Overridepublic void onScroll(AbsListView view, int firstVisibleItem, int visibleIte

0评论2016-09-1486

Android编程之截屏实现方法(包括scrollview与listview)
这篇文章主要介绍了Android编程之截屏实现方法,包括截取scrollview与listview屏幕的相关技巧,以及截屏图片的生成与保存技巧,需要的朋友可以参考下

0评论2015-11-2566

Android编程学习之抽象类AbsListView用法实例分析
这篇文章主要介绍了Android编程学习之抽象类AbsListView用法,较为详细的分析了抽象类AbsListView的功能、结构、定义及使用注意事项等,需要的朋友可以参考下

0评论2015-11-07118

Fragment里添加ListView不要用ListFragment
这篇文章主要介绍了Fragment里添加ListView不要用ListFragment,需要的朋友可以参考下

0评论2015-09-11355

Android中ListView异步加载图片错位、重复、闪烁问题分析及解决方案
在Android所有系统自带的控件当中,ListView这个控件算是用法比较复杂的了,关键是用法复杂也就算了,它还经常会出现一些稀奇古怪的问题,让人非常头疼,下面通过本篇文章给大家分享Android中ListView异步加载图片错位、重复、闪烁问题分析及解决方案,需要朋友可以参考

0评论2015-09-09137

更多推荐