Android Open Source - android Nav Drawer Item

From Project

Back to project page android.


The source code is released under:

Apache License

If you think the Android project android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

//  w w  w.  ja va2 s  . c om


import java.util.Arrays;
import java.util.List;

public class NavDrawerItem {

    static NavDrawerItem[] items = new NavDrawerItem[]{
            new NavDrawerItem(BoundedMapFragment.class, "Map"),
            new NavDrawerItem(ChefListFragment.class, "Chefs"),
            new NavDrawerItem(WineriesFragment.class, "Wineries"),
            new NavDrawerItem(BreweriesFragment.class, "Breweries"),
            new NavDrawerItem(FavoritesFragment.class, "Favorites")
    String itemName;
    Class<? extends Fragment> fragmentClass;
    Fragment fragment;
    public NavDrawerItem(Class<? extends Fragment> fragmentClass, String itemName) {
        this.fragmentClass = fragmentClass;
        this.itemName = itemName;

    public static List<NavDrawerItem> getItems() {
        return Arrays.asList(items);

    public Fragment getFragment() {
        if (fragment == null) {
            try {
                fragment = fragmentClass.newInstance();
            } catch (InstantiationException e) {
            } catch (IllegalAccessException e) {
                throw new RuntimeException("The fragment " + fragmentClass.getSimpleName() + " has no public default constructor.");
        return fragment;

    public String toString() {
        return itemName;

Java Source Code List