I'm calling on this acitvity as my main laucher this activity extends the SlidingActivity from this library https://github.com/jfeinstein10/SlidingMenu. When it creates a behindcontentview for the slidingmenu I use with a fragment. In this main activity I creating a custom view for a calendar there are icons that are drawed in this custom view. I want to toggle these icons so I'm using switches in the sliding menu fragment view but I'm getting a null pointer exception which log cat saids its happens in the listner when i toggle in the fragment where the switch is. So my code to clears the icons on a calendar that is made using the custom view in the main activty and does work with I use the code in the main activity but not within the toggle listner OnCheckedChangeListener.
Heres Mainactivity that calls on the slide menu and fragment to fill the slide menu
setBehindContentView(R.layout.menu_frame);
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
mFrag = new ColorFragment();
t.replace(R.id.menu_frame, mFrag);
t.commit();
// customize the SlidingMenu
SlidingMenu sm = getSlidingMenu();
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
//sm.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//redrawtest();
// setListener();
Heres my xml for this main activity.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.projects.shiftcalendar.CalendarView
android:id="@+id/view_month_calendar"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</com.projects.shiftcalendar.CalendarView>
</LinearLayout>
This is my fragment
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
return inflater.inflate(R.layout.slide_menu_toggle, null );
}
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Switch d = (Switch) getView().findViewById(R.id.monitored_switch1);
d.setOnCheckedChangeListener(this);
}
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
cv.redrawCalendarClearSymbol();
}
else {
cv.redrawCalendarClearSymbol();
}
}
}