2013-03-18 65 views
1

即使在ListView中有記錄時,也始終顯示ListView中的emptyView。 我使用SherlockFragment和我展示ListView控件的代碼如下:即使listView中有元素,也會始終顯示listView.SeptEmptyView

ViewGroup vg = (ViewGroup) getActivity().getLayoutInflater().inflate(
       R.layout.header_file, hotelListView, false); 
     hotelListView.addHeaderView(vg, null, false); 
     hotelListView.setOnItemClickListener(this); 
     hotelListView.setEmptyView(view.findViewById(R.id.empty)); 

和XML:

<ListView 
     android:id="@+id/hotel_list_view" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:cacheColorHint="#00000000" 
     android:paddingLeft="8dp" 
     android:persistentDrawingCache="scrolling" 
     android:scrollingCache="false" > 
    </ListView> 

    <TextView 
     android:id="@android:id/empty" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:text="No Results" /> 

所以以後我檢索結果形成的TextView仍顯示服務器在屏幕上,我可以看到屏幕上沒有結果文本,同時列表中有項目。我需要改變什麼,所以只有當列表中沒有元素時,纔會顯示@android:id/empty。由於

+1

我也一直有同樣的問題。 – ddmytrenko 2013-11-11 17:57:09

回答

1

看也不看的來源,我能想到的3級可能的錯誤,

  1. 的ListView不具備適配器套件。

  2. 如果重新實現了適配器,getCount()方法是否被正確重新實現?

  3. 你必須調用notifyDatasetChanged()嗎?內容從服務器獲取後。

+0

感謝您的回答,我在preExecute線程調用中添加了一個新的空視圖 – user1796624 2013-03-18 11:20:24

相關問題