ExpandableListView で大きな問題に直面しています。私の目標は、ユーザーがアイテムの位置をこの単一選択の展開可能なリスト ビューに変更できるようにすることです。
ユーザーが項目をクリックすると、項目がチェックされ、コンテキスト アクション バーが表示されます。したがって、ユーザーは次の方法でアイテムを上下に移動できます。
私が実装した上/下への移動機能は正常に動作します (これは、BaseExpandableListAdapter のデータソースである ArrayList 上のスワップ位置に基づいており、UI への変更を通知します)。残念ながら、チェックされたアイテムを移動すると、チェックされた状態が失われます...そして、アイテムを目に見える境界の外に移動すると(例では、「ロックされた」後または「添付ファイル」ビューの前)、展開可能なリストビューはスクロールしません新しい位置。
どうすればそれを達成できますか?
以下は、カスタム Adapter クラスにコード化された「moveDownFocusedItem()」です。
//This class is ok!
//Contains Group and Child position of an ExpandableListView
public class Position{
int GroupPosition;
int ChildPosition;
public boolean isChild(){
return (ChildPosition != AbsListView.INVALID_POSITION);
}
public Position getPreviousPosition(){
if(ChildPosition==AbsListView.INVALID_POSITION)
if(GroupPosition>0)
return new Position(GroupPosition-1);
else
return null;
else
if(ChildPosition>0)
return new Position(GroupPosition, ChildPosition-1);
else
return null;
}
public Position getNextPosition(){
if(ChildPosition==AbsListView.INVALID_POSITION)
if(GroupPosition<_fieldConfigurationList.size()-1)
return new Position(GroupPosition+1);
else
return null;
else
if(ChildPosition<_fieldConfigurationList.get(GroupPosition).getChildren().size()-1)
return new Position(GroupPosition, ChildPosition+1);
else
return null;
}
public Position(int groupPosition){
this.GroupPosition = groupPosition;
this.ChildPosition = AbsListView.INVALID_POSITION;
}
public Position(int groupPosition, int childPosition){
this.GroupPosition = groupPosition;
this.ChildPosition = childPosition;
}
}
public void moveDownFocusedItem(){
//This function returns the next position to move to
//(_focusedPosition is the current checked item position)
Position nextPosition = this._focusedPosition.getNextPosition();
//Swap ArrayList (This works!)
if(nextPosition!=null){
Collections.swap(this._fieldConfigurationList, //that's my datasource
this._focusedPosition.GroupPosition, //Start position for swapping
nextPosition.GroupPosition); //Destination position for swapping
//Set the new focused position (This works!)
this._focusedPosition = nextPosition;
//TODO:
//Now i have to call "SetItemChecked()" method to uncheck old focused position and check the new one.
//How to do it? How can i get the required "position" argument from _focusedPosition.GroupPosition and _focusedPosition.ChildPosition?
//And also...if the focused view has moved to an invisible position (such as the end of the expandablelistview) how can i scroll
//to this position?
//Notify changes (This works!)
this.notifyDataSetChanged();
}
}