티스토리 뷰


listview 설정부분

      final ExpandableListView listView = (ExpandableListView)v.findViewById(R.id.listview);
//     listView .setGroupIndicator(null); // child onoff 화살표를 없애려면 null 설정.
//     StateListDrawable groupIndicator = (StateListDrawable)getResources().getDrawable(R.drawable.arrow_sel);
//     myListView.setGroupIndicator(groupIndicator);
     MyAdapter myAdapter= new MyAdapter(this);
     myListView.setAdapter(myAdapter);


custom adapter 부분

  private class MyAdapter extends BaseExpandableListAdapter{
     private LayoutInflater mInflater;
     private Context mContext;
     
     public MyAdapter(Context context) {
      mContext = context;
      mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      
  }
     
  @Override
  public MyClass getChild(int arg0, int arg1) {
 
   return null /*child 부분 설정해놓으세요.*/;
  }

  @Override
  public long getChildId(int groupPosition, int childPosition) {
   // TODO Auto-generated method stub
   return childPosition;
  }

  @Override
  public View getChildView(int groupPosition, int childPosition,
    boolean isLastChild, View convertView, ViewGroup parent) {

   MyClass item = this.getChild(groupPosition, childPosition);
   
   if(convertView == null)convertView = mInflater.inflate(R.layout.item_child, null);
   
   if(item != null){
    TextView content = (TextView)convertView.findViewById(R.id.child);
   }
   
    
   return convertView;
  }

  @Override
  public int getChildrenCount(int groupPosition) {
   // TODO Auto-generated method stub
   return 1;
  }

  @Override
  public Object getGroup(int groupPosition) {
   // TODO Auto-generated method stub
   return null /*getGroup 부분설정해놓으세요*/;
  }

  @Override
  public int getGroupCount() {
   // TODO Auto-generated method stub
   return null /*getGroupCount부분설정해놓으세요*/;
  }

  @Override
  public long getGroupId(int groupPosition) {
   // TODO Auto-generated method stub
   return groupPosition;
  }

  @Override
  public View getGroupView(int groupPosition, boolean isExpanded,
    View convertView, ViewGroup parent) {
   
   MyClass item = myClassListData.get(groupPosition);
   
   if(convertView == null)convertView = mInflater.inflate(R.layout.group, null);
   
   if(item != null){
    TextView content = (TextView)convertView.findViewById(R.id.group);
   }
   
   
   
   return convertView;
  }

  @Override
  public boolean hasStableIds() {
   return false;
  }

  @Override
  public boolean isChildSelectable(int groupPosition, int childPosition) {
   // TODO Auto-generated method stub
   return true;
  }



xml부분. 일부
    <ExpandableListView
     android:id="@+id/listview"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:groupIndicator="@drawable/arrow_sel"
     android:indicatorLeft="0px"
     android:indicatorRight="0px"
     android:divider="#000000"
     android:dividerHeight="1px"
     android:childDivider="#000000"
    ></ExpandableListView>



위 코드는 임의로 작성한것으므로 비어있는부분을 채워야하며 작동 안할 수도있다.
그건 스스로 해결하자.

추가//
Group 닫기 collapseGroup(int)
Group 펼치기 expandGroup(int)

listView .setGroupIndicator(null); // child onoff 화살표를 없애려면 null 설정

//선택된 group만 open
   listView.setOnGroupClickListener(new OnGroupClickListener() {
   @Override
   public boolean onGroupClick(ExpandableListView parent, View v,
     int groupPosition, long id) {
    
    //클릭한 group이 열려있는 현재 group 이면 현재 group을 닫고 return;
    if(listView.isGroupExpanded(groupPosition)){
     listView.collapseGroup(groupPosition);
     return true;
    }
    
    //close
    for (int i = 0; i < myCassData.size(); i++) {
     if(listView.isGroupExpanded(i)){
            listView.collapseGroup(i);
     }
       }
    
    //open
    listView.expandGroup(groupPosition);
    
    return true; // 여기서 false 로하면 자체적으로 지원하는 코드를 타므로 true해서 막아주어야함.
   }
  });



 
댓글