簡體   English   中英

設置子視圖的可見性的最后一個位置

[英]Last place to set visibility of a child view

我正在使用Android APi3。我構建了一個包含兩個控件的容器控件:另一個容器(布局)和ListView。

在主容器控件中,我覆蓋了onLayout函數,以根據列表控件(第二個子視圖)中的項目將子視圖的可見性更改為GONE / VISIBLE。

問題是,當我使用GONE然后觸發事件並將其設置為VISIBLE時,將顯示第一個子控件,但隨后ListView不顯示該項目-ListView顯然有一個項目。

也許onLayout可能不是調用子控件的setVisibility的最后一個地方。 如果沒有,最好的地方是什么?

對於我的問題,使用INVISIBLE可以解決問題而不是GONE。

下面是代碼:@Override protected void onLayout(布爾值已更改,整數l,整數t,整數r,整數b){

    /* if there's no data to display, hide headerView */
    if (listView.getAdapter() == null || listView.getAdapter().getCount() == 0)
        headerView.setVisibility(INVISIBLE); // if set to GONE, it won't display the listView when there's only one item or unless it's refreshed 2nd time.
    else
        headerView.setVisibility(VISIBLE);

    super.onLayout(changed, l, t, r, b);
}

有什么想法嗎?

可能您需要使用yourAdapter.notifyDataSetChanged();刷新整個listView yourAdapter.notifyDataSetChanged(); 是你做的嗎...?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM