Android ListView on display/initialized event
I need to do some stuff when my ListView is finished displaying the items. As it is now I call the Notify开发者_StackOverflowDataSetChanged and then use the list.FirstVisiblePosition but the problem is that no items are visible at the time being called.
So how can I trigger my code when items are visible on screen?
The reason for this is that I need to do some work only for the visible items.
Thanks, Nicklas
What collection type are you using with the ListView? If you're using a "normal" collection type (e.g. System.Collections.Generic.List<T>
), then the ListView won't see any items you add to the collection after the ListView is constructed. You would need to use JavaList<T> instead.
See the example at the end of the 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.");
精彩评论