簡體   English   中英

ViewPager中的ListView-ListView中的項目保持空白

[英]ListView inside ViewPager - Items in ListView keep blank

我正面臨一個非常奇怪的現象。 我正在使用兼容性包中的ViewPager來顯示配置文件。

每個配置文件只是一個其中包含自定義元素的ListView。 每個元素都有兩個狀態:

  1. 有數據-顯示它
  2. 沒有數據-顯示占位符

每次在配置文件之間滑動時,都會重置項目對象中的數據。 當我刪除REST-Calls並將配置文件項留空時-應該顯示占位符-所有項均保持空白。

可能是什么問題呢?

編輯:/

這就是我在列表視圖中設置當前項目的方式。 PageViewAdapter似乎還可以,如果我使用靜態內容,那么一切正常。

    final TextView lblTitle = (TextView)convertView.findViewById(R.id.lblTitle);
    final LinearLayout llContent = (LinearLayout)convertView.findViewById(R.id.llContent);
    final ProfileItem item = getItem(userPosition);


    String title = item.getTitle();
    if(title == null || title.equals("")) {
        lblTitle.setVisibility(View.GONE);
    } else {
        lblTitle.setText(item.getTitle());
    }

    if(item.getContent().getParent() != null) {
        ((ViewGroup)item.getContent().getParent()).removeAllViews();
    }

    llContent.removeAllViews();
    llContent.addView(item.getContent());

這些項目看起來都非常相似,如下所示:

@Override
public View getContent() {
    if(isTextEmpty()) {
        return noTextTherePlaceholder;
    } else {
        return view;
    }
}

即使我只返回view或noTextTherePlaceholder,效果也保持不變。

如果我要在getView方法中像TextView那樣建立新視圖,那么一切都會按預期進行。

使用視圖分頁器,您必須將所有數據存儲在Activity.onCreate ,然后在ViewPagers適配器的onInstantiateItem使用該數據。

暫無
暫無

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

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