通过当月迭代获得的所有事件 [英] Iterating through current month to get all events

查看:112
本文介绍了通过当月迭代获得的所有事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日历应用程序。我想补充,其中显示当月的所有事件列表视图。

这是code我使用的回路,但它显示的而不是只有一个月的最后一个事件,的所有的事件:

 的for(int i = 0; I< _calendar.getActualMaximum(Calendar.DAY_OF_MONTH);我++){
        如果(isHoliday(I,月,年,DATE_VALUE))
        {
            字符串日期= I ++ getMonthForInt(月);
            CalendarEvents事件=新CalendarEvents();
            最终的ArrayList<事件> E =新的ArrayList<事件>();
            e.addAll(events.eventDetails(hijri_date [1],hijri_date [0]));            对于(INT J = 0; J< e.size(); J ++)
            {
               事件事件= e.get(J);
               summary_data =新摘要[]
                {
                   新的摘要(日期,event.eventdetails)
                };
            }
        }
    }
summaryAdapter =新SummaryAdapter(this.getActivity()getApplicationContext(),R.layout.listview_item_row,summary_data);calendarSummary =(ListView控件)v.findViewById(R.id.calendarSummary);
calendarSummary.setAdapter(summaryAdapter);

更新时间是code:

  CalendarEvents事件=新CalendarEvents();
最终的ArrayList<事件> E =新的ArrayList<事件>();
字符串日期;的for(int i = 0; I< _calendar.getActualMaximum(Calendar.DAY_OF_MONTH);我++){
    如果(isHoliday(I,月,年,DATE_VALUE))
    {
        日期= I + - +月+ - +年;        e.addAll(events.eventDetails(月,日));
        summary_data =新的概要[e.size()];        对于(INT J = 0; J< e.size(); J ++)
        {           事件事件= e.get(J);
           summary_data [J] =新的摘要(日期,event.eventdetails);
        }
    }
}


解决方案

您正在创建阵列每次和分配到相同的参考。这就是为什么最后一个代替一切。

  summary_data =新摘要[]
                {
                   新的摘要(日期,event.eventdetails)
                };

您知道大小进取,使创建尺寸的第一阵列,​​然后分配值指数

  summary_data =新的概要[e.size()]; 对于(....)
    {
 ......
    summary_data [J] =新的摘要(日期,event.eventdetails);
    }

/////

 如果(isHoliday(I,月,年,DATE_VALUE))
    {
       字符串日期= I + - +月+ - +年;

I have a calendar app. I want to add a listview which displays all the events for the current month.

This is the code which I am using to loop but it displays only the last event of the month, instead of ALL the events:

    for(int i = 0; i < _calendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++){
        if(isHoliday(i, month, year, date_value))
        {


            String date= i + " " + getMonthForInt(month);
            CalendarEvents events = new CalendarEvents();
            final ArrayList<Event> e = new ArrayList<Event>();
            e.addAll(events.eventDetails(hijri_date[1], hijri_date[0]));

            for (int j = 0; j < e.size(); j++)
            {
               Event event = e.get(j);
               summary_data = new Summary[]
                {
                   new Summary(date, event.eventdetails)
                };
            } 
        }
    }


summaryAdapter = new SummaryAdapter(this.getActivity().getApplicationContext(), R.layout.listview_item_row, summary_data);

calendarSummary = (ListView) v.findViewById(R.id.calendarSummary);
calendarSummary.setAdapter(summaryAdapter);

UPDATED CODE:

CalendarEvents events = new CalendarEvents();
final ArrayList<Event> e = new ArrayList<Event>();
String date;

for(int i = 0; i < _calendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++){
    if(isHoliday(i, month, year, date_value))
    {
        date = i + "-" + month + "-" + year;

        e.addAll(events.eventDetails(month, day));
        summary_data = new Summary[e.size()];

        for (int j = 0; j < e.size(); j++)
        {

           Event event = e.get(j);
           summary_data[j] = new Summary(date, event.eventdetails);
        } 
    }
}

解决方案

You are creating array every time and assigning to same reference. That is why last one replacing everything else.

 summary_data = new Summary[]
                {
                   new Summary(date, event.eventdetails)
                };

You know the size ahead, so create array with size first and then assign values to index

summary_data = new Summary[e.size()];



 for(....)
    {
 ......
    summary_data[j] = new Summary(date, event.eventdetails);
    }

/////

if(isHoliday(i, month, year, date_value))
    {
       String date = i + "-" + month + "-" + year;

这篇关于通过当月迭代获得的所有事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆