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) will pass in an int to represent the _id of the row in our database of the required Photo object. The other (onTagsListItemSelected) will pass a string that is the tag to be searched for and matched against rows in the wis_table_photos table.

We will handle this in three stages:

  1. First, we will add the required code to TitlesFragment.
  2. Next, we will add the code to TagsFragment.
  3. Finally, we will tie the whole thing together and implement the interface in MainActivity.

As we will be dipping in and out of existing methods as well as writing new ones, if you get disoriented in any way, simply open up the relevant files in the Chapter 24/Where Its Snap 3 folder where you can see all the code we add in this chapter complete in the appropriate places.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.237.77