반응형
package com.teamnote.Management.Adapter;
import java.util.HashSet;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
/**
* 커스텀 리스트뷰를 액티비티에 생성하는 핸들러 클래스
*/
public class DiaryExpendableListViewAdapter extends BaseExpandableListAdapter {
Context nContext;
LayoutInflater mInflater;
HashSet arSrc;
public String[] nArrGroups = {"a", "b", "c"};
public String[][] nArrChilds = {{"1", "2", "3"},{"1", "2", "3"},{"1", "2", "3"}};
public DiaryExpendableListViewAdapter(Context pContext,
HashSet arSrc) {
mInflater = (LayoutInflater) pContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.arSrc = arSrc;
this.nContext = pContext;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return nArrChilds[groupPosition][childPosition];
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public TextView getGenericView() {
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 64);
TextView textView = new TextView(nContext);
textView.setLayoutParams(lp);
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
textView.setPadding(36, 0, 0, 0);
return textView;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
TextView tvChilde = getGenericView();
tvChilde.setText(getChild(groupPosition, childPosition).toString());
return tvChilde;
}
@Override
public int getChildrenCount(int groupPosition) {
return nArrChilds[groupPosition].length;
}
@Override
public Object getGroup(int groupPosition) {
return nArrGroups[groupPosition];
}
@Override
public int getGroupCount() {
return nArrGroups.length;
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getGroup(groupPosition).toString());
return textView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}
반응형
'Android' 카테고리의 다른 글
| ViewFlipperListener / ViewFlipperHandler (0) | 2013.05.23 |
|---|---|
| SimpleExpandableListAdapter (0) | 2013.05.16 |
| interface를 상수처럼 사용하기 (0) | 2013.05.09 |
| ViewFlipper 와 OnTouchListener (0) | 2013.05.09 |
| 레이아웃 둥근 모서리 (0) | 2013.05.05 |
WRITTEN BY
,




