2011-09-13 45 views
1

當我的ListView完成顯示項目時,我需要做一些事情。 因爲它現在我調用NotifyDataSetChanged,然後使用list.FirstVisiblePosition,但問題是沒有項目在被調用時可見。顯示/初始化事件的Android ListView

那麼,當物品在屏幕上可見時,如何觸發我的代碼?

原因是我只需要爲可見物品做一些工作。

謝謝,尼克拉斯

回答

3

什麼樣的集合類型,你用ListView?如果您使用的是「正常」集合類型(例如System.Collections.Generic.List<T>),那麼在構建ListView後,ListView將不會看到您添加到集合中的任何項目。您需要改用JavaList<T>

參見在Collections binding overview的端部的示例:

// This fails: 
var badSource = new List<int> { 1, 2, 3 }; 
var badAdapter = new ArrayAdapter<int>(context, textViewResourceId, badSource); 
badAdapter.Add (4); 
if (badSource.Count != 4) // true 
    throw new InvalidOperationException ("this is thrown"); 

// this works: 
var goodSource = new JavaList<int> { 1, 2, 3 }; 
var goodAdapter = new ArrayAdapter<int> (context, textViewResourceId, goodSource); 
goodAdapter.Add (4); 
if (goodSource.Count != 4) // false 
    throw new InvalidOperaitonException ("should not be reached.");