Closed LorenzoZoia closed 7 years ago
@LorenzoZoia you could consume the event in the click listener if it's a subitem
Ok, how can I do that when I set the touch listener on the drawer ??
@LorenzoZoia don'T you have a DrawerItemClickListener to do something when the user clicks an item?
Yes, I am using the OnDrawerItemClickListener to start a new activity when I click on the subItem
This is my Drawer :
//Creation of the Drawer
final Drawer result = new DrawerBuilder()
.withActivity(fatherActivity)
.withHeader(R.layout.menu_header)
.withToolbar(toolbar)
.withCloseOnClick(false)
.withSliderBackgroundColor(fatherActivity.getResources().getColor(windowBackground))
.addDrawerItems(
item8,
item,
item1,
item2,
item3,
item4,
item5,
new DividerDrawerItem(),
item6,
item7
)
.build();
result.setSelection(-1);
result.setOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if(drawerItem != null){
Intent intent=null;
if(drawerItem.getIdentifier() == 4 && !(fatherActivity instanceof BottleBeerListActivity)){
intent = new Intent(fatherActivity, BottleBeerListActivity.class);
}
else if(drawerItem.getIdentifier() == 10 && !(fatherActivity instanceof HomeActivity)){
intent = new Intent(fatherActivity, HomeActivity.class);
}
if(intent != null){
fatherActivity.startActivity(intent);
fatherActivity.overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_right);
}
}
return true;
}
});
return result;
And this is how I create the Expandable:
PrimaryDrawerItem subItem1 = new PrimaryDrawerItem().withIdentifier(3).withName(R.string.drawer_item_spina).withLevel(2).withTextColor(Color.WHITE); subItem1.withIcon(R.drawable.ic_beer_tap); PrimaryDrawerItem subItem2 = new PrimaryDrawerItem().withIdentifier(4).withName(R.string.drawer_item_bottle).withLevel(2).withTextColor(Color.WHITE); subItem2.withIcon(R.drawable.ic_beerbottle); ExpandableDrawerItem item = new ExpandableDrawerItem().withName(R.string.drawer_item_beer).withTextColor(Color.WHITE).withSelectable(false).withSubItems( subItem1, subItem2 ).withIcon(R.drawable.ic_beer);
Setting an ExpandableItem
withSelectable(false)
will also prevent the closing, as shown in the DrawerActivity
of the sample app:
https://github.com/mikepenz/MaterialDrawer/blob/develop/app/src/main/java/com/mikepenz/materialdrawer/app/DrawerActivity.java#L138
I am encountering a strange problem. Despite I set .withCloseOnClick(false) when I click on an subItem of an ExpandableDrawerItem and I start a new activity, the entire Drawer get closed.