Automatic Code Generation for UI Elements

ThiesReinholdThiesReinhold DEMember
edited June 2014 in Xamarin.Android


just jumped into xamarin android development, I'm wondering, that there is just such a poor automatic code generation when designing new activities with the xamarin/Android layout designer?

Do be specific: I'd like to add a new button into the layout e.g. main.axml. And I would likely have a code reference to this element, so I can work with this element by code directly.

The only automatic code Generation happens in the Resource.Designer.cs, which creates me an integer constant with the element id.

And thats all? I've to connect this button by my own with "FindViewById(Resource.Id.CallButton);"?

I'm lazy and I don't want to type such boring things.

So I'm sure, I'm not the only person how misses this and that there must be a solution? Can anybody help?

Kind regards



  • PeterDavisPeterDavis USMember ✭✭✭

    You could always use T4 or Razor to generate your own templates. We make heavy use of both T4 and Razor in our own projects. We have an enterprise web app where roughly half of the code (mostly DB and Web Service code) is generated automatically from an XML file using T4 templates. A lot of the front-end .cshtml is generated from Razor templates (which is kind of strange because it's generating Razor code).

    But it would be rather trivial to write something to generate all the FindViewById calls for a .axml file.

    It's possible that one of the reasons they don't do this is, at least in my case, a lot of calls to FindviewById would be made that I'd never use. In fact, looking over our main app right now, I'd say it would probably produce about 3 times as many FindViewById calls as we would need. I'd personally rather hand code just the few that I need. Part of the trick to mobile development is keeping your code lean and fast.

Sign In or Register to comment.