question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Same event repeated three times

See original GitHub issue

Hi,

i can’t understand why an event is repeated three times in the same hour slot like in the screen. photo_2016-10-24_21-02-23

Here’s my code:

  // Get a reference for the week view in the layout.
    mWeekView = (WeekView) view.findViewById(R.id.weekView);

    mWeekView.goToHour(System.currentTimeMillis());

    mainActivity.fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mWeekView.goToToday();
            mWeekView.goToHour(System.currentTimeMillis());
        }
    });

    mWeekView.setOnEventClickListener(new WeekView.EventClickListener() {
        @Override
        public void onEventClick(WeekViewEvent event, RectF eventRect) {
            Toast.makeText(activity, "Event Clicked", Toast.LENGTH_SHORT).show();
        }
    });

    mWeekView.setMonthChangeListener(new MonthLoader.MonthChangeListener() {
        @Override
        public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
            // Populate the week view with some events.
            List<WeekViewEvent> events = new ArrayList<>();

            WeekViewEvent event = new WeekViewEvent(1,"Math Lecture with Mr. Adams",2016,10,24,18,0,2016,10,24,19,0);
            WeekViewEvent event1 = new WeekViewEvent(2,"event2",2016,11,24,18,0,2016,11,24,19,0);
            WeekViewEvent event2 = new WeekViewEvent(3,"event3",2016,12,24,18,0,2016,12,24,19,0);
            events.add(event);
            events.add(event1);
            events.add(event2);

            return events;
        }
    });

The layout is the same that you provided in the readme. How can i fix this?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

8reactions
prof18commented, Oct 27, 2016

I gave a deep look at the sample application and i’ve figured out what to do.

The code needed is the following:

        WeekViewEvent event = new WeekViewEvent(0,"Math Lecture with Mr. Adams",2016,10,27,23,0,2016,10,27,23,30);
        WeekViewEvent event1 = new WeekViewEvent(2,"event2",2016,11,24,18,0,2016,11,24,19,0);
        WeekViewEvent event2 = new WeekViewEvent(3,"event3",2016,12,24,18,0,2016,12,24,19,0);
        events.add(event);
        events.add(event1);
        events.add(event2);

        mWeekView.setMonthChangeListener(new MonthLoader.MonthChangeListener() {
            @Override
            public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
                // Populate the week view with some events.


                // Return only the events that matches newYear and newMonth.
                List<WeekViewEvent> matchedEvents = new ArrayList<WeekViewEvent>();
                for (WeekViewEvent event : events) {
                    if (eventMatches(event, newYear, newMonth)) {
                        matchedEvents.add(event);
                    }
                }
                return matchedEvents;
            }
        });

        return view;
    }

    /**
     * Checks if an event falls into a specific year and month.
     * @param event The event to check for.
     * @param year The year.
     * @param month The month.
     * @return True if the event matches the year and month.
     */
    private boolean eventMatches(WeekViewEvent event, int year, int month) {
        return (event.getStartTime().get(Calendar.YEAR) == year && event.getStartTime().get(Calendar.MONTH) == month-1) || (event.getEndTime().get(Calendar.YEAR) == year && event.getEndTime().get(Calendar.MONTH) == month - 1);
    }

We can find it in this class: https://github.com/alamkanak/Android-Week-View/blob/develop/sample/src/main/java/com/alamkanak/weekview/sample/AsynchronousActivity.java

0reactions
prof18commented, Oct 25, 2016

Thanks! It seems the best way to do it.

I’m gonna try and next I’ll write what I do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Threefold repetition - Wikipedia
In chess, the threefold repetition rule states that a player may claim a draw if the same position occurs three times during the...
Read more >
How many times to repeat an event with known probability ...
So the expected number of independent trials of your experiment (times) needed to obtain 120 successes is simply given by 120/0.01=12,000.
Read more >
If you have duplicate events on your iCloud Calendar
If you see duplicate calendars or events on your iPhone, iPad, iPod touch, Mac, or PC after you set up iCloud Calendar, follow...
Read more >
Same event is received multiple times
If I register a third message communication, I start getting same event three times. Is it possible to make each MessageReceiver get event...
Read more >
Probability of Repeated Events - YouTube
Worksheet:https://drive.google.com/file/d/1RB1girdC_yk3lm0_Iiqzt8XuhucC7q-H/view?usp=sharing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found