hsoetikno
hsoetikno

Reputation: 123

Android: How to automatically generate Java code from layout file?

Does anyone know of any Eclipse plug-in or anything that can be used to automatically generate Java code from layout file? As in, if I have an EditText in my layout file with the ID "@+id/txtHello", I expect something like the following to be generated:

EditText txtHello = (EditText) findViewById(R.id.txtHello);

Thanks for your time!

Harris :)

Upvotes: 9

Views: 10891

Answers (5)

tmorcinek
tmorcinek

Reputation: 93

There is new plugin that can generate Activity, Fragment, Adapter based on xml layout. Can also generate Menu related code (handling actions) for xml menu files. And has editable templates, so the user has more control on the generated data.

For Eclipse: http://tmorcinek.github.io/android-codegenerator-plugin-eclipse/

For Android Studio/IntelliJ IDEA: http://tmorcinek.github.io/android-codegenerator-plugin-intellij/

Upvotes: 1

ChrLipp
ChrLipp

Reputation: 15668

Normally there are three different ways to do this:

  1. at run time (via annotations per reflection)
  2. at compile time (via annotations or aspects)
  3. at development time (via code generators)

A good article to start is Clean Code in Android Applications.

Ad 1) Two solutions, see

Ad 2) Android Annotations, see http://androidannotations.org/

Ad 3) Two solutions, see

If there is more, please tell! I personally prefer 2) and therefore Android Annotations.

Hope that helps!

Upvotes: 10

Andreas Rudolph
Andreas Rudolph

Reputation: 1246

Use this online tool:

http://www.buzzingandroid.com/tools/android-layout-finder/

It simply gets the job done quickly. I use it every day.

Upvotes: 9

iamkristher
iamkristher

Reputation: 408

I use MotoDev Studio. It really saves time.

Upvotes: 0

Diego Torres Milano
Diego Torres Milano

Reputation: 69198

There is an Eclipse plugin that does exactly what you want , I guess: http://marketplace.eclipse.org/content/lazy-android

Upvotes: 5

Related Questions