9

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 :)

5 Answers 5

10

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!

Sign up to request clarification or add additional context in comments.

1 Comment

9

Use this online tool:

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

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

Comments

5

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

Comments

1

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/

1 Comment

this should be the accepted answer, working as expected on android studio 1.5.1
0

I use MotoDev Studio. It really saves time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.