Acabo de encontrar una solución para evitar que el sistema para mostrar este comportamiento equivocado.
Hay dos escenarios que usan código diferente para el SectionIndexer
para funcionar.
El primer caso es que utiliza FastScrollbar-Thumb para navegar a la siguiente sección. Suponiendo que los grupos son sus secciones de los métodos anulado para la aplicación del SectionIndexer
se vería así:
@Override
public int getPositionForSection(int section) {
return section;
}
// Gets called when scrolling the list manually
@Override
public int getSectionForPosition(int position) {
return ExpandableListView.getPackedPositionGroup(
expandableListView
.getExpandableListPosition(position));
}
El segundo escenario es el caso de que el desplazamiento por la lista de forma manual y las barras de desplazamiento rápido se mueven de acuerdo a las secciones, no todos los artículos. Por tanto, el código es el que:
@Override
public int getPositionForSection(int section) {
return expandableListView.getFlatListPosition(
ExpandableListView.getPackedPositionForGroup(section));
}
// Gets called when scrolling the list manually
@Override
public int getSectionForPosition(int position) {
return ExpandableListView.getPackedPositionGroup(
expandableListView
.getExpandableListPosition(position));
}
Como se puede ver estos dos comportamientos no pueden jugar juntos sin mayor adopción.
La solución para que ambos funcionen es captar el caso cuando alguien está desplazándose por mano (es decir, desplazándose mediante el tacto). Esto se puede hacer con la implementación de la interfaz OnScrollListener
con la clase adaptador y la puso sobre la ExpandableListView
:
public class MyExpandableListAdapter extends BaseExpandableListAdapter
implements SectionIndexer, AbsListView.OnScrollListener {
// Your fields here
// ...
private final ExpandableListView expandableListView;
private boolean manualScroll;
public MyExpandableListAdapter(ExpandableListView expandableListView
/* Your other arguments */) {
this.expandableListView = expandableListView;
this.expandableListView.setOnScrollListener(this);
// Other initializations
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
this.manualScroll = scrollState == SCROLL_STATE_TOUCH_SCROLL;
}
@Override
public void onScroll(AbsListView view,
int firstVisibleItem,
int visibleItemCount,
int totalItemCount) {}
@Override
public int getPositionForSection(int section) {
if (manualScroll) {
return section;
} else {
return expandableListView.getFlatListPosition(
ExpandableListView.getPackedPositionForGroup(section));
}
}
// Gets called when scrolling the list manually
@Override
public int getSectionForPosition(int position) {
return ExpandableListView.getPackedPositionGroup(
expandableListView
.getExpandableListPosition(position));
}
// Your other methods
// ...
}
que corrigió el problema para mí.
¿Las filas de la lista son de diferentes tamaños? –
puedes ... por favor ... publicar tu XML – Rockin
Publica tu código/xml –