Recently, in order to conform to the requirements of the UI, the layout of the child in Expandablelistview was redefined, and the split line was redefined for better control of the split line in the future.
Ideas are as follows,
In the past, when we implemented the level two menu, we had to load layout layouts for group and child separately, and show them through getview after loading, which is exactly what we can use to differentiate and set different styles.
The style of the previous split line is relatively single, and to adapt to the requirements of the art of some difficulties, so I wrote it into a layout, we can be in the Expandablelistview adapter processing, first of all, we can first normal data filling, But the split lines are set to empty in the layout,
That's the effect, and in the custom divider view,
Myexpandablespliteline (Baseexpandablelistadapter expandablelistview) {This
(Expandablelistview, R.layout. Group_divider, R.layout. child_divider);
}
ChildLine) {this.
= Expandablelistview;
this. = groupline;
this. = childline;
}
First you have to comb the expandable execution process.
@Override
getchildtypecount () {
elv. Getchildtypecount () + 1;
}
@Override
getgrouptypecount () {
elv. Getgrouptypecount () + 1;
}
@Override
getgrouptype (groupposition) {
elv. Getgrouptype ( GROUPPOSITION/2): Getgrouptypecount ()-1;
}
@Override
getchildtype (childposition) {
elv. Getchildtype (GROUPPOSITION/2, CHILDPOSITION/2): Getchildtypecount ()-1;
}
To distinguish whether the view you want to draw currently is a view or a split line view
isview (index) {
index% 2 = = 0;
}
When filling into a new adapter, be aware that count has doubled.
@Override
getgroupcount () {
groupcount =elv. GetGroupCount ();
GroupCount * 2;
}
@Override
getchildrencount (groupposition) {
elv. Getchildrencount (groupposition);
ChildCount * 2;
}
@Override
Object getgroup (groupposition) {
(Isview (groupposition)
) ELV. Getgroup (GROUPPOSITION/2);
Else
groupposition;
}
@Override
Object getchild (childposition) {
elv. Getchild ( Groupposition, childposition);
}
@Override
getgroupid (groupposition) {
return getcombinedgroupid (groupposition);
}
@Override
getchildid (childposition) {
getcombinedchildid (groupposition, childposition);
}
@Override
hasstableids () {
elv. Hasstableids ();
}
The last time we draw the view we just need to distinguish
@Override
View Getgroupview (isexpanded, view Convertview, ViewGroup parent) {
(Isview (groupposition))//Judge the current view is Groupview, direct getgroupview on the line
elv. Getgroupview ( Groupposition, isexpanded, Convertview, parent);
Judging by the type, it is currently a split line viewif(Convertview = =NULL&& Getgrouptype (groupposition) = = Getgrouptypecount ()-1)returnLayoutinflater.from (Parent.getcontext ()). Inflate ( This.Groupline, parent,false);Else returnConvertview; } @Override PublicView Getchildview (intGroupposition,intChildposition,BooleanIslastchild, View Convertview, ViewGroup parent) {if(Isview (groupposition) &&!isview (childposition))returnELV. Getchildview (Groupposition, Childposition, Islastchild, Convertview, parent);if(Getchildtype (groupposition, childposition) = = Getchildtypecount ()-1)returnLayoutinflater.from (Parent.getcontext ()). Inflate (ChildLine, parent,false);Else returnConvertview; }
The results of the operation are as follows:
The reason for the preliminary decision should appear here
@Override
getgroupcount () {
groupcount =elv. GetGroupCount ();
GroupCount * 2;
}
@Override
getchildrencount (groupposition) {
elv. Getchildrencount (groupposition);
ChildCount * 2;
}
Childview also includes split line view, if it is a split line view, we can get to the ChildCount should be 0
@Override
getchildrencount (groupposition) {
(Isview (groupposition)) {
elv. Getchildrencount (groupposition% 2);
ChildCount * 2;
Else
0;
}
Groupposition is now doubling, meaning it is no longer a 0,1,2,3,4,5 style
It's 0,2,4,6. So when it comes to GROUPPOSITION/2 this is also involved when dealing with click events
@Override
View Getgroupview (isexpanded, view Convertview, ViewGroup parent) {
(Isview (groupposition))//Judge the current view is Groupview, direct getgroupview on the line
elv. Getgroupview ( GROUPPOSITION/2, isexpanded, Convertview, parent);
Judging by type, current is split line view
(getgrouptype (groupposition) = = Getgrouptypecount ()-1)
Layoutinflater.from (Parent.getcontext ()). Inflate (this. Grouplinefalse);
Else
convertview;
}
Final Effect Diagram:
There are some rough areas that need to be improved .
GitHub Address: Https://github.com/uvfv1991/MyExpandableListViewLine