Open tchape opened 7 years ago
I have the same problem. I have a fragment which contains in a Activity.I wanna show the fragment with AgendaCalendarView. But each time I click then the app crashed. So did you solve it? The following is my code.
`package com.creatureox.worldcup.fragment;
import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup;
import com.creatureox.worldcup.R; import com.github.tibolte.agendacalendarview.AgendaCalendarView; import com.github.tibolte.agendacalendarview.CalendarPickerController; import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent; import com.github.tibolte.agendacalendarview.models.CalendarEvent; import com.github.tibolte.agendacalendarview.models.DayItem;
import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.Locale;
public class CalenderFragment extends Fragment implements CalendarPickerController{
AgendaCalendarView mAgendaCalendarView;
private View view;
private Context context;
public CalenderFragment() {
// Required empty public constructor
}
public static CalenderFragment newInstance(){
CalenderFragment homeFragment=new CalenderFragment();
return homeFragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_calender, container, false);
Calendar minDate = Calendar.getInstance();
Calendar maxDate = Calendar.getInstance();
minDate.add(Calendar.MONTH, -2);
minDate.set(Calendar.DAY_OF_MONTH, 1);
maxDate.add(Calendar.YEAR, 1);
List<CalendarEvent> eventList = new ArrayList<>();
mockList(eventList);
mAgendaCalendarView.init(eventList, minDate, maxDate, Locale.getDefault(), this);
return view;
}
private void mockList(List<CalendarEvent> eventList) {
Calendar startTime1 = Calendar.getInstance();
Calendar endTime1 = Calendar.getInstance();
endTime1.add(Calendar.MONTH, 1);
BaseCalendarEvent event1 = new BaseCalendarEvent("Thibault travels in Iceland", "A wonderful journey!", "Iceland",
ContextCompat.getColor(getContext(), R.color.orange_dark), startTime1, endTime1, true);
eventList.add(event1);
Calendar startTime2 = Calendar.getInstance();
startTime2.add(Calendar.DAY_OF_YEAR, 1);
Calendar endTime2 = Calendar.getInstance();
endTime2.add(Calendar.DAY_OF_YEAR, 3);
BaseCalendarEvent event2 = new BaseCalendarEvent("Visit to Dalvík", "A beautiful small town", "Dalvík",
ContextCompat.getColor(getContext(), R.color.yellow), startTime2, endTime2, true);
eventList.add(event2);
}
@Override
public void onDaySelected(DayItem dayItem) {
}
@Override
public void onEventSelected(CalendarEvent event) {
}
@Override
public void onScrollToDate(Calendar calendar) {
}
} `
I don't open my calendarView in fragment my source MainActivity package seed.prie.iuc.myiucap;
import android.content.res.Configuration; import android.os.Bundle; import android.support.design.widget.NavigationView; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.view.GravityCompat; import android.support.v4.view.ViewPager; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.MenuItem; import android.widget.Toast;
import com.astuetz.PagerSlidingTabStrip;
import seed.prie.iuc.myiucap.fragment.calendarViewFragment;
public class MainActivity extends AppCompatActivity{ private DrawerLayout drawerLayout; private DrawerLayout mDrawer; private Toolbar toolbar; private NavigationView nvDrawer; private ActionBarDrawerToggle drawerToggle;
}
my source calendarViewFragment package seed.prie.iuc.myiucap.fragment;
import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup;
import com.github.tibolte.agendacalendarview.AgendaCalendarView; import com.github.tibolte.agendacalendarview.CalendarPickerController; import com.github.tibolte.agendacalendarview.models.BaseCalendarEvent; import com.github.tibolte.agendacalendarview.models.CalendarEvent; import com.github.tibolte.agendacalendarview.models.DayItem;
import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.Locale;
import seed.prie.iuc.myiucap.MainActivity; import seed.prie.iuc.myiucap.R; import seed.prie.iuc.myiucap.edt.emploiTemps;
/**
public class calendarViewFragment extends Fragment implements CalendarPickerController { private static final String LOG_TAG = emploiTemps.class.getSimpleName(); AgendaCalendarView mAgendaCalendarView;
}