[mono-android] java translation, mark murphy 05 fancy viewlist example

Michael Isbell michael.isbell at gmail.com
Thu Mar 17 14:28:39 EDT 2011


I seem to remember that Java methods are overridden by default, and C#
methods are static by default -- IOW Java uses a VMT a lot more than C#
does--C# regarded not making it the default as a speed optimization.

it's aaaaalll coming back...



On Thu, Mar 17, 2011 at 2:06 PM, Michael Prenez-Isbell <
michael.isbell at gmail.com> wrote:

> thank you!!!
>
> i'm creating a git repository for these examples
>
> Sent from my iPhone
>
> On Mar 17, 2011, at 12:11 PM, Jonathan Pryor <jpryor at novell.com> wrote:
>
> > There were two bugs with your translation.
> >
> > On Mar 16, 2011, at 1:41 AM, Michael Isbell wrote:
> >> FILE 1
> > ...
> >>    public class LunchList : Activity
> >>    {
> >>        IList<Restaurant> model=new List<Restaurant>();
> >
> > Change 1: make this a JavaList<Restaurant>, not a List<Restaurant>.
> Currently, IList<T> marshaling is "[In]" (to use a P/Invoke equivalent).
> That is, the contents of the list are copied into a Java-side
> java.util.ArrayList, and that copy is passed to Java code.
> >
> > This is a problem because later, in LunchList.onSave(), you call
> adapter.Add(restaurant), which alters the java-side list but NOT the
> managed-side list.
> >
> > By using JavaList<T> instead, you have a single list, so when the list is
> changed by Java code the changes are visible within managed code.
> >
> >> FILE 2
> > ...
> >> public class RestaurantAdapter : ArrayAdapter<Restaurant>
> > ...
> >>        public View getView(int position, View convertView,
> >>                                                ViewGroup parent) {
> >
> > Change 2: this is wrong. The Java code doesn't make it obvious, but this
> is supposed to override a base class method. (Specifically, the sample code
> _should_ have used @Override to make this clearer, but @Override is
> optional, so Java missing @Override doesn't break anything. Not overriding a
> method in C#, meanwhile, _does_ break things.)
> >
> > Thus, you want:
> >
> >        public override View GetView(int position, View convertView,
> ViewGroup parent) {
> >
> > With those two changes, the sample works for me.
> >
> > - Jon
> >
> > _______________________________________________
> > Monodroid mailing list
> > Monodroid at lists.ximian.com
> >
> > UNSUBSCRIBE INFORMATION:
> > http://lists.ximian.com/mailman/listinfo/monodroid
>



-- 
Mike Isbell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/mailman/private/monodroid/attachments/20110317/b1c6d6f2/attachment-0001.html 


More information about the Monodroid mailing list