2011-12-12 55 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; 
}