((MainActivity) getActivity()).refreshViewPager();
The error message is:
java.lang.NullPointerException:
at de.ubik.terminkalender.DayFragment$8$1.onDismiss (DayFragment.java:1378)
at android.app.Dialog$ListenersHandler.handleMessage (Dialog.java:1749)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6692)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1358)
I've got the following structure: MainActivity (with viewpager) -> DayFragment (as a Fragment) -> Dialog. When I close the dialog I want to check if there is a button clicked in the dialog. When clicked, then refresh viewpager in MainActivity. How to achieve that?
–
–
as mentioned by @Deev you will always get a null and the solution for this is that call your Dialog from some of the method which has getActivity as a parameter.
sample code:
//call this from your fragment
showDialog(getActivity());
and in your fragment place this somewhere
public void showDialog(final Activity activity){
final EventPopup eventpopup = new EventPopup(activity, readevent);
eventpopup.show();
eventpopup.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
if(eventpopup.getDelete()) {
((MainActivity)activity).refreshViewPager();
} else if (eventpopup.getEdit()) {
((MainActivity) activity).doEditEvent(readevent, eventpopup.getEditAll());
this will work for sure.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.