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

   2016-09-08 0
核心提示:CalendarListViewA custom ListView combine with CalendarView which interactive each other. just watch demo to get more detail.Demo Apk Download:CalendarListView.apk Downloadcompile 'com.kelin.calendarlistview:library:1.0.1' 中文文档: Calend

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.
 
标签: ListView 开源
反对 0举报 0 评论 0
 

免责声明:本文仅代表作者个人观点,与乐学笔记(本网)无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
    本网站有部分内容均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,若因作品内容、知识产权、版权和其他问题,请及时提供相关证明等材料并与我们留言联系,本网站将在规定时间内给予删除等相关处理.

  • Android 自定义ListView adapter(zt)
    Android 自定义ListView adapter(zt)
    本文讲实现一个自定义列表的Android程序,程序将实现一个使用自定义的适配器(Adapter)绑定数据,通过contextView.setTag绑定数据有按钮的ListView。系统显示列表(ListView)时,首先会实例化一个适配器,本文将实例化一个自定义的适配器。实现自定义适配器
    12-01 ListView
  • Android ListView 优化之 getView 与 ViewHolder 是如何工作的?
    Android ListView 优化之 getView 与 ViewHolde
    Android中我们经常会用到ListView,然后ListView到底是如何通过ViewHolder去优化的?1.常见的适配器中利用ViewHolder去优化ListView的代码@Overridepublic View getView(int position, View convertView, ViewGroup parent) {ViewHolder viewHolder;if (conve
    11-07 ListView
  • listviewd优化---viewHolder的封装
    listviewd优化---viewHolder的封装
    android项目中如果使用listview控件,则在优化上我们一般使用viewHolder保证列表项的布局convertView可以被重用避免多次重新绘制。 一般方法中getView的写法@Overridepublic View getView(int position, View convertView, ViewGroup parent) {ViewHolder vie
    11-07 安卓开发
  • Android ListView优化之局部刷新(更新)(非notifyDataSetChanged)
    Android ListView优化之局部刷新(更新)(非no
    在Android开发中我们经常会用到listview的数据和界面刷新动作,我们每次可能会用到的都是Adapter.notifyDataSetChanged()方法。这个方法的原理是利用观察者模式对我们的数据源进行监听,当我们的数据源发生变化的时候,会调用Adapter的getView()方法进行整个
    11-04 ListView
  • 基础篇章:关于 React Native 之 ListView 组件的讲解
    基础篇章:关于 React Native 之 ListView 组件
    我们讲完ScrollView组件,其实顺其自然的就应该讲解ListView,对于前段和移动端的开发人员应该非常熟悉这样的控件吧,具体是做什么的,我感觉不用我讲了吧。我们来看看它怎么使用吧。大家好,我是ListView,我是React Native大家族中基础组件中,一个核心组件
  • Android ListView 使用不同对象加载不同布局
    Android ListView 使用不同对象加载不同布局
    因为未知原因,突然想到了关于一个 List 集合里面能否添加不同对象的问题,因为我们平时开发过程中,关于List 的比较常规的写法就是:ListXXX list = new ArrayListXXX();这让我形成了一种 List 里面就只能添加一种类型的对象的潜在想法(或许是 Java 基础不
    10-31 ListView
  • Android应用性能优化系列视图篇——ListView自适应导致的严重性能问题
    Android应用性能优化系列视图篇——ListView自
    ListView是Android中最常用的视图之一,使用的频率仅仅次于三大基础布局,虽然由于使用性和扩展性等原因备受争议,且尽管后来出现了RecyclerView的替代方案,但是ListView仍然广泛地使用在我们的项目中。自从ListView出道至今,已经不知道衍生出了多少问题,
  • android中listview的一些样式设置
    在 Android中,ListView是最常用的一个控件,在做UI设计的时候,很多人希望能够改变一下它的背景,使他能够符合整体的UI设计,改变背景背很简单只需要准备一张图片然后指定属性 android:background=”@drawable/bg”,不过不要高兴地太早,当你这么做以后,发
    10-13 ListView
  • React Native填坑之旅--ListView篇
    列表显示数据,基本什么应用都是必须。笔者写作的时候RN版本是0.34。今天就来从浅到深的看看React Native的ListView怎么使用。首先是使用写死的数据,之后会使用网络请求的数据在界面中显示。最后加上一个ActivityIndicator,网络请求的过程中显示Loading图标
  • RecyclerView、ListView 实现单选列表的优雅之路.
    RecyclerView、ListView 实现单选列表的优雅之
    一 概述: 这篇文章需求来源还是比较简单的,但做的 优雅 仍有值得挖掘的地方。 需求来源:一个类似饿了么这种 电商优惠券的选择界面 : 其实就是 一个普通的列表,实现了 单选 功能,效果如图:(不要怪图渣了,我撸了四五遍,公司录出来的GIF就这么渣。。。
点击排行