2013-05-01 97 views
0

我有一個Activity來擴展ListActivity以顯示一些搜索結果。除非沒有結果(適配器爲空),否則一切正常,我無法使EmptyView顯示描述此內容的文本。見下面的代碼。當ListAdapter爲空時ListView.EmptyView不顯示

protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     var description = Intent.GetStringExtra("Description"); 
     var partResults = this.partsClient.GetPartsSearchResults(description); 
     this.results = partResults; 
     var textView = new TextView(ListView.Context); 
     textView.Text = "No Results..."; 
     this.ListView.EmptyView = textView; 
     this.ListAdapter = new PartsListAdapter(this, results); 

    } 

有人能看到什麼是錯的這段代碼,爲什麼文「無結果......」不會當適配器結果是空的顯示?

回答

2

插入下面的調用以前setEmptyView()

((ViewGroup)this.ListView.getParent()).addView(textView); 

這是因爲EmptyView作品通過切換顯示/隱藏在佈局上已經存在的視圖的狀態,它不會添加查看到你的佈局。

相關問題