Coding the communications interface
We know that TitlesFragment
needs a way to communicate with ViewFragment
, but also TagsFragment
needs a way of telling TitlesFragment
which tag it would like to use for the criteria to search for database entries with the matching tag.
This same interface will handle all this work. MainActivity
can then implement the interface and handle the inter-fragment communication.
Create a new class called ActivityComs
and code it into our interface by editing it to exactly the code shown next:
public interface ActivityComs { void onTitlesListItemSelected(int pos); void onTagsListItemSelected(String tag); }
We now have two methods we can use for communicating between our Fragment
classes and MainActivity
. One (onTitlesListItemSelected ...
Get Android Programming for Beginners now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.