如何添加链接页面抽屉菜单

时间:2015-10-04 21:42:09

标签: java android materialdrawer

我正在使用mikepenz抽屉。但小问题前:我需要精英包,但精英包购买谷歌播放。我需要那里的指导。

如何添加精英项目去elitepage类?

 result = new Drawer()
            .withActivity(this)
            .withToolbar(toolbar)

            .withHeader(R.layout.header)
            .addDrawerItems(
                    new PrimaryDrawerItem().withName(R.string.category_all).withIdentifier(Category.ALL.id).withIcon(FontAwesome.Icon.faw_image),
                    new PrimaryDrawerItem().withName(R.string.category_featured).withIdentifier(Category.FEATURED.id).withIcon(FontAwesome.Icon.faw_star),
                    new PrimaryDrawerItem().withName(R.string.category_elit).withIcon(FontAwesome.Icon.faw_asterisk),
                    new SectionDrawerItem().withName(R.string.category_section_categories),
                    new PrimaryDrawerItem().withName(R.string.category_buildings).withIdentifier(Category.BUILDINGS.id).withIcon(FontAwesome.Icon.faw_building),
                    new PrimaryDrawerItem().withName(R.string.category_food).withIdentifier(Category.FOOD.id).withIcon(FontAwesome.Icon.faw_cutlery),
                    new PrimaryDrawerItem().withName(R.string.category_nature).withIdentifier(Category.NATURE.id).withIcon(FontAwesome.Icon.faw_tree),
                    new PrimaryDrawerItem().withName(R.string.category_animals).withIdentifier(Category.ANIMALS.id).withIcon(FontAwesome.Icon.faw_paw),
                    new PrimaryDrawerItem().withName(R.string.category_people).withIdentifier(Category.PEOPLE.id).withIcon(FontAwesome.Icon.faw_user),
                    new PrimaryDrawerItem().withName(R.string.category_fashion).withIdentifier(Category.FASHION.id).withIcon(FontAwesome.Icon.faw_diamond),
                    new PrimaryDrawerItem().withName(R.string.category_objects).withIdentifier(Category.OBJECTS.id).withIcon(FontAwesome.Icon.faw_book),
                    new PrimaryDrawerItem().withName(R.string.category_vehicles).withIdentifier(Category.VEHICLES.id).withIcon(FontAwesome.Icon.faw_car),
                    new PrimaryDrawerItem().withName(R.string.category_technology).withIdentifier(Category.TECHNOLOGY.id).withIcon(FontAwesome.Icon.faw_lightbulb_o),
                    new PrimaryDrawerItem().withName(R.string.category_games).withIdentifier(Category.GAMES.id).withIcon(FontAwesome.Icon.faw_gamepad),
                    new PrimaryDrawerItem().withName(R.string.category_space).withIdentifier(Category.SPACE.id).withIcon(FontAwesome.Icon.faw_rocket),
                    new PrimaryDrawerItem().withName(R.string.category_quotes).withIdentifier(Category.QUOTES.id).withIcon(FontAwesome.Icon.faw_quote_left),
                    new PrimaryDrawerItem().withName(R.string.category_abstract).withIdentifier(Category.ABSTRACT.id).withIcon(FontAwesome.Icon.faw_paint_brush),
                    new PrimaryDrawerItem().withName(R.string.category_material).withIdentifier(Category.MATERIAL.id).withIcon(FontAwesome.Icon.faw_dot_circle_o),
                    new PrimaryDrawerItem().withName(R.string.category_minimal).withIdentifier(Category.MINIMAL.id).withIcon(FontAwesome.Icon.faw_times_circle),
                    new PrimaryDrawerItem().withName(R.string.category_stocks).withIdentifier(Category.STOCKS.id).withIcon(FontAwesome.Icon.faw_mobile_phone),
                    new PrimaryDrawerItem().withName(R.string.category_others).withIdentifier(Category.OTHERS.id).withIcon(FontAwesome.Icon.faw_archive)
            )
            .withSelectedItem(1)
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l, IDrawerItem drawerItem) {
                    if (drawerItem != null) {
                        if (drawerItem instanceof Nameable) {
                            toolbar.setTitle(((Nameable) drawerItem).getNameRes());
                        }
                        if (onFilterChangedListener != null) {
                            onFilterChangedListener.onFilterChanged(drawerItem.getIdentifier());
                        }
                        if (drawerItem  = category_elite) {
                            Intent i = new Intent(MainActivity.this, ElitePack.class);
                        } //it's here!!
                    }

                }
            })
            .build();

1 个答案:

答案 0 :(得分:0)

首先,你应该尝试改善你的问题。你的问题是什么,以及你挣扎的是什么并不是很清楚。

查看您的代码我已经看到了一些问题,如:

if (drawerItem = category_elite) {
    Intent i = new Intent(MainActivity.this, ElitePack.class);
}

您尝试使用之前未定义的drawerItem来定义category_elite

您必须为类别Category.BUILDINGS.id定义另一个类别elite,并将其定义为标识符。

.withIdentifier(Category.ELITE.id)

onItemClick监听器中,您可以检查identifier是否相等

if (drawerItem.getIdentifier() == Category.ELITE.id) {
    //start the activity   
}

然后实现所需的逻辑。