Android Programming The Big Nerd Ranch Guide, 3rd Edition

(Brent) #1
Creating the menu

257

Define CrimeListFragment.onCreate(Bundle) and let the FragmentManager know that
CrimeListFragment needs to receive menu callbacks.


Listing 13.7  Receiving menu callbacks (CrimeListFragment.java)


public class CrimeListFragment extends Fragment {


private RecyclerView mCrimeRecyclerView;
private CrimeAdapter mAdapter;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,


You can run CriminalIntent now to see your menu (Figure 13.8).


Figure 13.8  Icon for the New Crime action item in the toolbar


http://www.ebook3000.com

Free download pdf