2011-12-12 51 views

回答

1

设置父IEW vlayout PARAMS hieght在你BaseExpandableListAdapter,这样可以隐藏你父

+0

我试图 parent.getLayoutParams()高度= 0。 parent.invalidate();我试过了: parent.setLayoutParams 但它启动ClassCastException :( 你真的试过这个或你猜对了吗? – Giorgio

11

1)隐藏与组指标零:

android:groupIndicator="@android:color/transparent" 

2)为你想要的空组返回一个空的FrameLayout,像这样:

@Override 
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 

    //By default the group is hidden 
    View view = new FrameLayout(context); 

    String groupTitle = getGroup(groupPosition).toString(); 

    //in case there's more than one group and the group title is not empty then show a TextView within the group bar 
    if(getGroupCount() > 1 && !groupTitle.isEmpty()) { 

     view = getGenericView(); 
     ((TextView)view).setText(groupTitle); 
    } 

    return view; 

} 
如果你想证明你有从getGroupView方法以编程方式添加一个ImageView的一组指标

expandableListView.expandGroup(GROUP_ID); 

4):

3)呼叫expandGroup为组你没有显示条组。查看这篇博客文章了解隐藏/显示组指示器的更多信息:Hiding group indicator for empty groups

+0

返回一个FrameLayout做了窍门。谢谢:) – Atmaram

+0

感谢您的技巧。这是它为我工作的唯一答案。无论如何,这是不是有点哈克?我不明白为什么不是一种“官方”的方式来隐藏标题。 – kazbeel

+0

这是个窍门:View view = new FrameLayout(context); – Derzu

9

我有同样的问题,这解决了我的问题。 在Listview的适配器中,将以下内容添加到getGroupView。

if (groupPosition == 0) { 
    convertView = layoutInflater.inflate(R.layout.blank_layout, null); 

} else { 
    convertView = layoutInflater.inflate(R.layout.group_indicator_cell,null); 
} 

这将使列表的第0组空白。

其中空白布局是布局,其中一些视图里面有layout_height = 0dp。 它的工作原理!

+0

我刚才试过这个,它确实有效,但它对可扩展列表中的其余可见组导致了一些奇怪的行为。尽管如此,聪明的解决方案! – LargeGlasses

2

而不是返回一个空的布局,我穿过布局中的所有孩子,并在没有数据时调用view.setVisibility(View.Gone)

@Override 
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 

    LinearLayout lo; 

    if (convertView != null) { 
     lo = (LinearLayout) convertView; 
    } else { 
     lo = (LinearLayout) mLayoutInflater.inflate(R.layout.list_item_group_header, parent, false); 
    } 

    int visibility = mData.size() == 0 ? View.GONE : View.VISIBLE; 
    for (int i = 0; i < lo.getChildCount(); i++) { 
     lo.getChildAt(i).setVisibility(visibility); 
    } 
    return lo; 
}