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.

WeekView in Fragment: You must provide a MonthChangeListener

See original GitHub issue

Hi. I am trying to implement an AndroidWeekView in a fragment (in which it is the only view), but the app crashes with the error java.lang.IllegalStateException: You must provide a MonthChangeListener, although I have provided one in onCreateView(). The same code worked flawlessly in an activitiy’s onCreate(), so I assume there to be an issue with the implementation of the fragment. See my code (shortened to the essentials for readability) below for details. Thanks for any help!

public class TimetableFragment extends Fragment{
private WeekView mWeekView;
public static TimetableFragment newInstance(String param1, String param2) {
        TimetableFragment fragment = new TimetableFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }
@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View mView = inflater.inflate(R.layout.fragment_timetable, container, false);
        mWeekView = (WeekView) mView.findViewById(R.id.weekView);
        setupWeekview();
        //return view
        return mView;
    }
private void setupWeekview(){
        if (mWeekView != null) {
            //set listener for month change
            mWeekView.setMonthChangeListener(new MonthLoader.MonthChangeListener() {
                @Override
                public List<? extends WeekViewEvent> onMonthChange(int i, int i1) {
                    return new ArrayList<WeekViewEvent>();
                    //TODO: Handle month change (return new list of events)
                }
            });

            //set listener for event click
            mWeekView.setOnEventClickListener(new WeekView.EventClickListener() {
                @Override
                public void onEventClick(WeekViewEvent event, RectF eventRect) {
                    //TODO: Handle event click
                }
            });

            //set event long press listener
            mWeekView.setEventLongPressListener(new WeekView.EventLongPressListener() {
                @Override
                public void onEventLongPress(WeekViewEvent event, RectF eventRect) {
                    //TODO: Handle event long press
                }
            });
}}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
JHthe4commented, Aug 25, 2016

Well, apparently now it works again. It turns out the problem wasn’t an underlying bug in the library, or worse, android’s definition of fragments: I forgot to remove the old weekView from my layout-v21 xml file. So, for anyone reading this in the future: triple check that you don’t have a second weekView being loaded anywhere! @caske33, I’m so sorry for wasting your time!

0reactions
entropitorcommented, Aug 26, 2016

No problem. I’m glad it’s resolved!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Week View (alamkanak - library) triplicates event names
The method onMonthChange(int newYear, int newMonth) runs three time. Once for actual month, once for previous month and once for next month. Therefore...
Read more >
example.fussen.baselibrary.widget.weekview.WeekView ... - Tabnine
isInEditMode()) throw new IllegalStateException("You must provide a MonthChangeListener"); if (!isInEditMode() && (mFetchedPeriod < 0 || mFetchedPeriod !=
Read more >
Calendar View Tutorial With Example In Android Studio
In this we set selected week background color and week separator line color and finally perform setOnDateChangeListener event to be notified upon selected...
Read more >
Date & Time Pickers - Android Week View - The Android Arsenal
We have to provide the events of a // month every time the month changes on the week view. mWeekView.setMonthChangeListener(mMonthChangeListener); ...
Read more >
addict - OSCHINA - 中文开源技术交流社区
Features Week view calendar Day view calendar Custom styling Horizontal and ... it change the way we bank and play,fragmentation our time,there is...
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