仅在可展开项内展开一项而不折叠
Expand one item only inside expandable item without being collapsed
我有一个抽屉,里面有多个可扩展的项目,例如 "main1"(可扩展的项目)在里面 "main2-1","main2-2","main2-3"(可扩展的item) inside "main3-1","main3-2","main3-3" (normal item)
我只想让 "main2" 级别的一个 ExpandedItem (main2-1, 2-1, 2-3)
也处于"main1"
的水平
我试过 result.getAdapter().withOnlyOneExpandedItem(true);
,其中 "result" 是我正在使用的抽屉库 - 它不起作用,因为折叠 "main2" 关卡而不是展开关卡的第一项
此外,this 方法在第三次点击不同的可扩展项时不起作用 - 我在代码后面加上日志记录以确保应用程序进入它,但它不会折叠前一个
if(previousExpandableItemPosition != position) {
result.getAdapter().collapse(previousExpandableItemPosition);
previousExpandableItemPosition = position;
}
我制作了一个方法,我将其放置在扩展项的 onClick 中,我只想扩展其中一个,这是为了帮助其他任何人
if (position != previousPosition && previousPosition != 0 && previousIdentifier != drawerItem.getIdentifier()) { // WithOnlyOneExpandableItem
IDrawerItem itemx = result.getAdapter().getItem(previousPosition);
if (itemx.isExpanded()) {
itemx.withIsExpanded(true);
result.updateItem(itemx);
} else {
if(previousPosition > position){ // user is going upward
itemx = result.getAdapter().getItem(previousPosition + result.getAdapter().getItem(position).getSubItems().size());
if (itemx.isExpanded()) {
itemx.withIsExpanded(true);
result.updateItem(itemx);
}else{Log.i("ppppppppppppp", String.valueOf(previousPosition + (previousPosition - position)));}
}else if(previousPosition > position){ // user is going downward
itemx = result.getAdapter().getItem(previousPosition + (previousPosition
+ result.getAdapter().getItem(previousPosition).getSubItems().size()));
if (itemx.isExpanded()) {
itemx.withIsExpanded(true);
result.updateItem(itemx);
}else{Log.i("ppppppppppppp", String.valueOf(previousPosition + (previousPosition - position)));}
}
}
} else if (previousPosition != 0 && previousIdentifier == drawerItem.getIdentifier()) {
//if the drawer item is collapsed after expanding then deselect it
EnterTimes++;
if(!result.getAdapter().getItem(position).isExpanded()){
EnterTimes=1;
}
if(EnterTimes <2){
result.getAdapter().getItem(position).withSetSelected(false);
result.updateItem(drawerItem);
}
}
previousIdentifier = (int) drawerItem.getIdentifier();
previousPosition = position;
在onCreate之前int previousPosition = 0, previousIdentifier = 0;
我有一个抽屉,里面有多个可扩展的项目,例如 "main1"(可扩展的项目)在里面 "main2-1","main2-2","main2-3"(可扩展的item) inside "main3-1","main3-2","main3-3" (normal item)
我只想让 "main2" 级别的一个 ExpandedItem (main2-1, 2-1, 2-3) 也处于"main1"
的水平我试过 result.getAdapter().withOnlyOneExpandedItem(true);
,其中 "result" 是我正在使用的抽屉库 - 它不起作用,因为折叠 "main2" 关卡而不是展开关卡的第一项
此外,this 方法在第三次点击不同的可扩展项时不起作用 - 我在代码后面加上日志记录以确保应用程序进入它,但它不会折叠前一个
if(previousExpandableItemPosition != position) {
result.getAdapter().collapse(previousExpandableItemPosition);
previousExpandableItemPosition = position;
}
我制作了一个方法,我将其放置在扩展项的 onClick 中,我只想扩展其中一个,这是为了帮助其他任何人
if (position != previousPosition && previousPosition != 0 && previousIdentifier != drawerItem.getIdentifier()) { // WithOnlyOneExpandableItem
IDrawerItem itemx = result.getAdapter().getItem(previousPosition);
if (itemx.isExpanded()) {
itemx.withIsExpanded(true);
result.updateItem(itemx);
} else {
if(previousPosition > position){ // user is going upward
itemx = result.getAdapter().getItem(previousPosition + result.getAdapter().getItem(position).getSubItems().size());
if (itemx.isExpanded()) {
itemx.withIsExpanded(true);
result.updateItem(itemx);
}else{Log.i("ppppppppppppp", String.valueOf(previousPosition + (previousPosition - position)));}
}else if(previousPosition > position){ // user is going downward
itemx = result.getAdapter().getItem(previousPosition + (previousPosition
+ result.getAdapter().getItem(previousPosition).getSubItems().size()));
if (itemx.isExpanded()) {
itemx.withIsExpanded(true);
result.updateItem(itemx);
}else{Log.i("ppppppppppppp", String.valueOf(previousPosition + (previousPosition - position)));}
}
}
} else if (previousPosition != 0 && previousIdentifier == drawerItem.getIdentifier()) {
//if the drawer item is collapsed after expanding then deselect it
EnterTimes++;
if(!result.getAdapter().getItem(position).isExpanded()){
EnterTimes=1;
}
if(EnterTimes <2){
result.getAdapter().getItem(position).withSetSelected(false);
result.updateItem(drawerItem);
}
}
previousIdentifier = (int) drawerItem.getIdentifier();
previousPosition = position;
在onCreate之前int previousPosition = 0, previousIdentifier = 0;