MaterialDrawer 中的 expandableitem 中的 updateBadge Android
updateBadge in expandableitem in MaterialDrawer Android
我在 expandableItem 中显示徽章。当用户单击该项目时,我希望 expandableItem 中的徽章消失,只在子项目中显示徽章。
但是在我的代码中,当我点击时,徽章消失但子项目没有显示。我做错了什么?
谢谢
result = new DrawerBuilder()
.withActivity(this)
.withToolbar(appbar)
.withHasStableIds(true)
.withAccountHeader(headerResult)
.addDrawerItems(
...
new ExpandableBadgeDrawerItem().withName("Collapsable Badge").withIcon(R.drawable.ic_menu_exp).withIdentifier(18).withSelectable(false).withBadge("2").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700)).withSubItems(
new SecondaryDrawerItem().withName("CollapsableItem").withLevel(2).withIcon(R.drawable.ic_menu_send).withIdentifier(2000).withBadge("2").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700)),
new SecondaryDrawerItem().withName("CollapsableItem 2").withLevel(2).withIcon(R.drawable.ic_menu_send).withIdentifier(2001)
)
)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem != null) {
if (drawerItem.getIdentifier() == 18) {
result.updateBadge(18, null);
}
}
return false;
}
})
.withSavedInstance(savedInstanceState)
.build();
我检查了一下,你是对的,这基本上是底层 FastAdapter
处理可扩展项的方式的结果,如果更新父项,它将折叠子项。这将在 FastAdapter
的 v3 中得到改进,直到那时请使用以下代码段:
//get the item from our drawerItem
ExpandableBadgeDrawerItem d = (ExpandableBadgeDrawerItem) drawerItem;
//remove the badge
d.withBadge((StringHolder) null);
//notify the adapter that the item was changed
result.getAdapter().notifyItemChanged(result.getPosition(18));
我在 expandableItem 中显示徽章。当用户单击该项目时,我希望 expandableItem 中的徽章消失,只在子项目中显示徽章。 但是在我的代码中,当我点击时,徽章消失但子项目没有显示。我做错了什么? 谢谢
result = new DrawerBuilder()
.withActivity(this)
.withToolbar(appbar)
.withHasStableIds(true)
.withAccountHeader(headerResult)
.addDrawerItems(
...
new ExpandableBadgeDrawerItem().withName("Collapsable Badge").withIcon(R.drawable.ic_menu_exp).withIdentifier(18).withSelectable(false).withBadge("2").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700)).withSubItems(
new SecondaryDrawerItem().withName("CollapsableItem").withLevel(2).withIcon(R.drawable.ic_menu_send).withIdentifier(2000).withBadge("2").withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700)),
new SecondaryDrawerItem().withName("CollapsableItem 2").withLevel(2).withIcon(R.drawable.ic_menu_send).withIdentifier(2001)
)
)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem != null) {
if (drawerItem.getIdentifier() == 18) {
result.updateBadge(18, null);
}
}
return false;
}
})
.withSavedInstance(savedInstanceState)
.build();
我检查了一下,你是对的,这基本上是底层 FastAdapter
处理可扩展项的方式的结果,如果更新父项,它将折叠子项。这将在 FastAdapter
的 v3 中得到改进,直到那时请使用以下代码段:
//get the item from our drawerItem
ExpandableBadgeDrawerItem d = (ExpandableBadgeDrawerItem) drawerItem;
//remove the badge
d.withBadge((StringHolder) null);
//notify the adapter that the item was changed
result.getAdapter().notifyItemChanged(result.getPosition(18));