android - How to communicate between two child Fragments inside a Nested Fragment -


i can communicate between 2 fragments of activity callback interface. following way, have implemented interface in parentfragment communicate.

but in case of activity, using -

 @override     public void onattach(activity activity) {         super.onattach(activity);         try {             mcallback = (onheadlineselectedlistener) activity;         } catch (classcastexception e) {             throw new classcastexception(activity.tostring()                     + " must implement onheadlineselectedlistener");         }     } 

and in current case, using mcallback = (onheadlineselectedlistener) getparentfragment(); instead of mcallback = (onheadlineselectedlistener) activity;. working well. approach okay? or should thread instead onattach()?

the cast thing ensure object instance of class implements given interface (in case onheadlineselectedlistener). it's irrelevant @ point type of object activity, fragment or else. long implements interface need, fine.


Comments

Popular posts from this blog

Issues changing the value of an element in an array in matlab -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

vb.net - Alternative to the T-SQL AS keyword -