0

내 프로젝트의 탭 하나를 나타내는 조각이 있습니다. 이 프래그먼트는 ExpandableListAdapater를 호스팅합니다. 확장 가능한 목록은 일부 정보를 표시하는 그룹당 하나의 TextView 자식입니다.ExpandableListView에서 현재 그룹 축소 방법

내가 얻으려고하는 것은 확장 된 TextView에서 두 번 탭을 구현하는 것입니다. TextView를 두 번 탭하면 해당 그룹이 축소됩니다.

나는 어댑터 내부에서 그룹을 축소하려고했지만 어떤 이유로 SO가 발생합니다. 나는 GestureDetector를 구현해야한다는 것을 알고 있지만, 이것을 어댑터 나 심지어 조각 안에 구현할 수는 없다.

내 조각 :

public class FragmentProgramInfo extends Fragment 
{ 
View view; 
ExpandableListView expandableListView; 
ExpandableListAdapterProgramInfo expandableListAdapterProgramInfo; 

public FragmentProgramInfo() 
    {} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    { 
    view = inflater.inflate(R.layout.fragment_program_info, container, false); 
    return view; 
    } 

@Override 
public void onViewCreated(View view, Bundle savedInstanceState) 
    { 
    super.onViewCreated(view, savedInstanceState); 
    expandableListAdapterProgramInfo = new ExpandableListAdapterProgramInfo(getActivity()); 
    expandableListView = (ExpandableListView) view.findViewById(R.id.ELV_program_info_list); 
    expandableListView.setAdapter(expandableListAdapterProgramInfo); 
    } 
} 

내 Adapater : 처음에는

public class ExpandableListAdapterProgramInfo extends BaseExpandableListAdapter 
{ 
Activity context; 
View masterView; 
private String[] listGroups; 
private String[][] listChilds; 

public ExpandableListAdapterProgramInfo(Activity context) 
    { 
    this.context = context; 
    interfaceExpandableListAdapterProgramInfo = (InterfaceExpandableListAdapterProgramInfo) context; 
    masterView = context.getWindow().getDecorView().findViewById(android.R.id.content); 

    /// Intitialize strings of listGroups and listChilds 
    } 

@Override 
public View getGroupView(final int listGroupPosition, boolean isExpanded, View view, ViewGroup viewGroup) 
    { 
    LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    if(view == null) 
     view = layoutInflater.inflate(R.layout.list_group_program_info, viewGroup, false); 
    TextView tvListGroupProgramInfo = (TextView) view.findViewById(R.id.TV_list_group_program_info); 
    tvListGroupProgramInfo.setText(getGroup(listGroupPosition).toString()); 
    return view; 
    } 

@Override 
public View getChildView(final int listGroupPosition, final int listChildPosition, boolean isLastChild, 
         View view, ViewGroup viewGroup) 
    { 
    LayoutInflater inflater = context.getLayoutInflater(); 
    view = inflater.inflate(R.layout.list_child_program_info, viewGroup, false); 
    TextView tvListChildProgramInfo = (TextView) view.findViewById(R.id.TV_list_child_program_info); 
    tvListChildProgramInfo.setText(listChilds[listGroupPosition][listChildPosition]); 
    return view; 
    } 

/// Override other methods of ELV 
} 

답변

0

당신은 당신이

private int lastExpandedPosition = -1;// last index selected 
private ExpandableListAdapterProgramInfo expandableListView; //your expandable listview 
... 

expandableListView.setOnGroupExpandListener(new OnGroupExpandListener() { 

    @Override 
    public void onGroupExpand(int groupPosition) { 
      if (lastExpandedPosition != -1 
        && groupPosition != lastExpandedPosition) { 
       expandableListView.collapseGroup(lastExpandedPosition); 
      } 
      lastExpandedPosition = groupPosition; 
    } 
}); 
+0

나는 이것이 어떻게 도움이되는지 잘 모르겠습니다. – Samuel

0

시도처럼 어떤 일을 시도 할 수 있습니다 마지막으로 선택한 위치 을 감지해야 this :

@Override 
public void onGroupExpanded(int groupPosition){ 
    //collapse the old expanded group, if not the same 
    //as new group to expand 
    if(groupPosition != lastExpandedGroupPosition){ 
     listView.collapseGroup(lastExpandedGroupPosition); 
    } 

    super.onGroupExpanded(groupPosition);   
    lastExpandedGroupPosition = groupPosition; 
} 

희망 하시겠습니까? 행운을 빕니다!