Passing Arguments between tabbed fragments


Well i wanted to take CriminalIntent to the next level. I added tabs using one Activity and 3 fragments.

The first fragment (tab 1 - default) lists categories of crimes.
Tab 2 is the List of all crimes (crimelistfragment)(if you click on the tab its self) - want it to display only the crimes that fall in the category if a list item is clicked on tab 1.
Tab 3 is the details of the crime (crimefragment) Displays first crime when the tab is clicked – want it to display correct crime when a list item is clicked in Tab 2.

What I would like to now implement is passing the UUID’s between the tabs when the item is clicked in the list. In onListItemClick I currently use:
TabHost host = (TabHost) getActivity().findViewById(;
to move between the tabs.

How do I pass the data between the tab fragments? I have tired everything I can think of.
I have tried passing the data to the hosting Activity and then down to the next tab. I cant get this to work. I am clearly missing something in my understanding.

BTW: your book is outstanding. I got my masters in computer science before java came out and I haven’t programmed in years but using what I have learned in your book I have been able to make a few really nice apps. Thank you. I think I am need to come to one of your classes soon. :slight_smile:

Thank you so much for your help.


1- It’s possible to update the arguments once they’re set. E.g., inside your fragment:

Bundle bundle = getArguments();
bundle.putSerializable(KEY_UUID, new UUID());

Then have your activity call methods on your fragment to alter those values.

2- I strongly recommend checking out using the Action Bar for tabs, not TabHost. As I’m sure you’ve seen already, TabHost is a little grody.

We’re really glad to hear you’re getting a lot of out the book! Thank you so much for the compliments.