-1

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

如何添加精英项目去精英页面类?

 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();
4

1 回答 1

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   
}

然后你实现你需要的逻辑。

于 2015-10-05T10:13:59.500 回答