Android.Runtime.JavaList<T>  has fixed it, thank you.


On 16/10/11 03:13, Jonathan Pryor wrote:
> On Oct 15, 2011, at 10:44 AM, Stuart Johnson wrote:
>> I have a List<>  with an ArrayAdapter that shows the contents of that list.
>>
>> If I make a change to one of those items in the List<>, and do
>> NotifyDataSetChanged() in the UI thread, I can see those changes.  But
>> if I .Add to the List<>, I cant see the new items.
> We expose standard .NET interface collection types instead of Java interface 
> collection types, e.g. IList<T>  instead of java.util.List<E>, to facilitate 
> greater code sharing. This is generally good. :-)
>
> However, the Java code still wants/needs/requires a java.util.List<E>, so 
> there are two ways we could have gone with this:
>
> 1) Write a java.util.List<E>  implementation which wraps an IList<T>, 
> delegating all List<E>  method calls. This means that every collection 
> traversal from Java would require several Java->managed transitions.
>
> 2) Copy the IList<T>  into an internal java.util.ArrayList<E>  wrapper on 
> "input", and let Java manipulate the Java collection. This would allow 
> ~direct Java access to the collection, though invocation of individual 
> elements would require a Java->managed transition.
>
> For reasons I'm not entirely sure of (probably performance), we went with 
> (2), which is exactly what you're seeing -- when you add an element to your 
> List<T>, Android doesn't see it. Android doesn't see it because it's not 
> present in the Java-side collection, because a new collection was created and 
> copied when creating the original ArrayAdapter instance.
>
>       http://docs.xamarin.com/android/advanced_topics/api_design#Collections
>
> The workaround is to use an Android.Runtime.JavaList<T>, which wraps a 
> Java-side java.util.ArrayList, and thus adding an element to a JavaList<T>  
> will make it immediately visible to Java code.
>
>   - Jon
>
> _______________________________________________
> Monodroid mailing list
> [email protected]
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid

_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to