Automatically generate Android boilerplate code from Layout XML

Java has a bit of a reputation for being too verbose which is a common stick for haters to beat it with. But as Bjarne Stroustrup says “There are only two kinds of languages: the ones people complain about and the ones nobody uses”.

But it’s a valid criticism so you want your IDE to generate the boring code for you which is where the Lazy Android Eclipse plugin from Ryan Mattison comes in. After you install it you right click on any Android Layout and select Fast Layout -> Generate Activity. It’s then supposed to write code into your class in focus but it only pastes to the clipboard for me where I can easily use in my activites of course.

So here’s my original layout XML:


And here’s the code it generated:
[prettify] /**********DECLARES*************/
private RadioGroup radio_type;
private RadioButton radio_car;
private RadioButton radio_motorcycle;
private RadioButton radio_truck;
private RadioButton radio_bus;
radio_type = (RadioGroup) findViewById(;
radio_car = (RadioButton) findViewById(;
radio_motorcycle = (RadioButton) findViewById(;
radio_truck = (RadioButton) findViewById(;
radio_bus = (RadioButton) findViewById(;
/* Please visit for updates */[/prettify]

Very handy. Get the plugin here.

Published by Georgie Casey

student. Google+

Leave a comment

Your email address will not be published. Required fields are marked *