![](/img/trans.png)
[英]ExpandableListView shows only one groupView and no childView
[英]I want to remove the groupView of an ExpandableListView when there is no childView in it
請原諒我的提問方式和我的英語。 我想在沒有childView的情況下刪除我的ExpandableListView的 groupView 。我通過使用翻新2獲得我的Expandedable childView 。 請耐心等待,因為我在開發android方面有一點技巧:)
這是我的ExpandableListView適配器代碼
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<Headers> _listDataHeader;
private HashMap<Headers, List<FixturesObject>> _listDataChild;
public ExpandableListAdapter(Context context, List<Headers> listDataHeader,
HashMap<Headers, List<FixturesObject>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@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 Object getChild(int groupPosition, int childPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
Headers headers = (Headers) 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.textHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
ImageView imageView = (ImageView) convertView.findViewById(R.id.image);
lblListHeader.setText(headers.getNameLeague());
imageView.setImageResource(headers.getImageID());
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
FixturesObject fixturesObject =(FixturesObject) 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 HomeTeamName = (TextView) convertView.findViewById(R.id.home_team_name);
HomeTeamName.setText(fixturesObject.getMatchHometeamName());
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
一種方法是編輯getGroupView
以在getChildrenCount( groupPosition ) == 0
返回高度為0dp的空FrameLayout,並在有子代的情況下使用當前代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.