2016-10-03 3 views
0

나는 Expandablelistview을 만들었으며 그룹 간 간격을 추가하고 몇 가지 시도를했지만 아무 것도 효과가 없었습니다. 내가 시도한 첫 번째 것은 XMLandroid:dividerHeight을 추가하는 것이었고 그룹과 어린이 사이에 간격이 생겼지 만 그룹 사이에는 간격 만 있으면됩니다. 또한이 시도했습니다 suggestion,하지만 제대로 내 코드에서 구현할 수 없습니다. 여기 expandablelistview의 그룹 간 갭

은 내 ExpandableListAdapter : 난 정말 솔루션은 당신이 당신의 ExpandableListAdapterprivate ExpandableListView exp;를 선언 한 다음 매개 변수로 넣어 가지고 있듯이 누군가가 나 :

답변

0

을 도울 수 있기를 바랍니다

public class ExpandableListAdapter extends BaseExpandableListAdapter { 

    private Context _context; 
    private List<String> _listDataHeader; // header titles 
    private HashMap<String, List<String>> _listDataChild; 


    public ExpandableListAdapter(Context context, List<String> listDataHeader, 
           HashMap<String, List<String>> listChildData) { 
     this._context = context; 
     this._listDataHeader = listDataHeader; 
     this._listDataChild = listChildData; 
    } 

    @Override 
    public Object getChild(int groupPosition, int childPosititon) { 
     return this._listDataChild.get(this._listDataHeader.get(groupPosition)) 
       .get(childPosititon); 
    } 

    @Override 
    public long getChildId(int groupPosition, int childPosition) { 
     return childPosition; 
    } 

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

     final String childText = (String) getChild(groupPosition, childPosition); 

     if (convertView == null) { 
      LayoutInflater infalInflater = (LayoutInflater) this._context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = infalInflater.inflate(R.layout.list_item, null); 
     } 

     TextView txtListChild = (TextView) convertView 
       .findViewById(R.id.lblListItem); 

     txtListChild.setText(childText); 
     return convertView; 
    } 

    @Override 
    public int getChildrenCount(int groupPosition) { 
     return this._listDataChild.get(this._listDataHeader.get(groupPosition)) 
       .size(); 
    } 

    @Override 
    public Object getGroup(int groupPosition) { 
     return this._listDataHeader.get(groupPosition); 
    } 

    @Override 
    public int getGroupCount() { 
     return this._listDataHeader.size(); 
    } 

    @Override 
    public long getGroupId(int groupPosition) { 
     return groupPosition; 
    } 

    @Override 
    public View getGroupView(int groupPosition, boolean isExpanded, 
          View convertView, ViewGroup parent) { 
     String headerTitle = (String) getGroup(groupPosition); 
     if (convertView == null) { 
      LayoutInflater infalInflater = (LayoutInflater) this._context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = infalInflater.inflate(R.layout.list_group, null); 
     } 


     TextView lblListHeader = (TextView) convertView 
       .findViewById(R.id.lblListHeader); 
     lblListHeader.setTypeface(null, Typeface.BOLD); 
     lblListHeader.setText(headerTitle); 

     return convertView; 
    } 

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

    @Override 
    public boolean isChildSelectable(int groupPosition, int childPosition) { 
     return true; 
    } 

당신의 mainactivity 추가에

public ExpandableListAdapter(Context context, List<String> listDataHeader, 
          HashMap<String, List<String>> listChildData, ExpandableListView exp) { 
    this._context = context; 
    this._listDataHeader = listDataHeader; 
    this._listDataChild = listChildData; 
    this.exp = exp; 
} 

: 같은 public ExpandableListAdapter 그래서 당신은 볼 것이다 그래서 구문 분석 할 때 ExpandableListview는 뭔가 살펴 보겠습니다 당신에 의해 분할 높이를 설정할 수 있습니다 마침내

ExpandableListAdapter mylistadapter = new ExpandableListAdapter(this, listDataHeader, listDataChild, expListView);

:

exp.setDividerHeight(10);