<< 안드로이드 ExpandableListView 구현 관련 >>


1. ExpandableListView 는 목록을 누르면, child 목록이 나오는것이다.


2. ExpandableListView에서 사용하는 아답터는 BaseExpandableListAdapter 이다.


3. BaseExpandableListAdapter는 

   extends Object

   implements ExpandableListAdapter HeterogeneousExpandableList 이다.

   주로 ExpandableListAdapter 인터페이스를 구현한다.


4.  ExpandableListAdapter 인터페이스에서 필수로 구현해야 할 것들은 아래와 같다.

     http://developer.android.com/reference/android/widget/ExpandableListAdapter.html 에서

    1) abstract Object getGroup(int groupPosition)  : 그룹값을 얻는다.  List자료구조에 그룹데이터를 넣는다.

        사용예) 


	private ArrayList mGroupList = null;
	@Override
	public String getGroup(int groupPosition) {
		return mGroupList.get(groupPosition);
	}
	@Override
	public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
		...
		viewHolder.tv_row_group.setText(getGroup(groupPosition));
		...
	}  


    2) abstract Object getChild(int groupPosition, int childPosition) : 차일드값을 얻는다. List의 List자료구조에 차일드 데이터를 넣는다.

       사용예)


  
       private ArrayList> mChildList = null;
	@Override
	public String getChild(int groupPosition, int childPosition) {
		return mChildList.get(groupPosition).get(childPosition);
	}
	@Override
	public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
		...
		viewHolder.tv_row_child.setText(getChild(groupPosition, childPosition));
		...
	}


5.  사용방법은 일반 List와 동일하다

      사용예)


   
private ExpandableListView mListView;	// 목록
private MyExpandableAdapter mBaseExpandableAdapter;	// 아답터
private ArrayList mGroupList = null;
private ArrayList> mChildList = null;

mBaseExpandableAdapter = new MyExpandableAdapter(mContext, mActivity, mGroupList, mChildList, null);
mListView.setAdapter(mBaseExpandableAdapter);



참고 링크 : http://arabiannight.tistory.com/entry/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9CAndroid-ExpandableListView-%EB%A7%8C%EB%93%A4%EA%B8%B0


http://arabiannight.tistory.com/373


http://blog.ulug.or.kr/go/777

+ Recent posts