Question

I use eclipse for android development, and I find it very annoying that every time I create an activity or add new views to my activity, I need to create the references to views in my layout. I am looking for some kind of eclipse plugin that can generate the calls to findViewById() from the layout. I couldn't really find anything because I didn't know what it would be named. It would be very useful and time saving if that kind of plugin existed.

EDIT: The answers you gave are great. Can these tools also add more references to an existing activity so I don't have to manually do that when I add a view to the layout?

Was it helpful?

Solution 2

Try the morcinek code generator. Its really simple to use.

This are the steps to install the plugin:

http://tmorcinek.wordpress.com/2011/11/30/eclipse-plugin-for-automatic-generation-of-activity-code-from-xml-layout-file/

After install process you may want to configurate a package to get the classes built by the generator, on the IDE -> Window -> Preferences on Bookmark Android Code Generator you can change that parameter.

The plugin does need a better interface for custom activities, still you could get the code, its really simple to make the changes you need, at least the inline listeners.

This solution doesnt work to modify classes you already have, that would be a really good improvement... i'll give it a try in a couple days with more time.

OTHER TIPS

You can use https://github.com/JakeWharton/butterknife library for View Injections.

You can also get eclipse plugin https://marketplace.eclipse.org/content/lazy-android for the same.

But the ButterKnife library is frequently being contributed by android devs than the mentioned eclipse plugin. With this library, you can also avoid instantiating listeners yourself by just using like,

@OnClick(R.id.submit) void submit() {
// TODO call server...
}

For View injections, simply,

@InjectView(R.id.user) EditText username;
@InjectView(R.id.pass) EditText password;

So, it will compile as,

 username = (EditText) findViewById(R.id.user);
 password = (EditText) findViewById(R.id.pass);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top