Skip to content
Advertisement

Communication Between DialogFragment and Fragment

I am trying to pass information from my alert dialog to my second fragment (I am using tabbed activity layout).

I want to pass information from alert dialog to fragment when I click on my ImageView, but my app keep crashing until I implement my interface inside MainActivity.java. My main mission here is to open alert dialog which contains several buttons. When I click first button I want to print “Test br 3” but it does not work inside my Fragment, it only works inside my MainActivity.java where method prints “Test br 2”.

My Main Activity

JavaScript

My Fragment

JavaScript

My Alert Dialog

JavaScript

Advertisement

Answer

I changed getChildFragmentManager() instead of getFragmentManager() in the show() call. Second thing is onAttach() to listener = (DataTransfer) getParentFragment(); instead of context.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement