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

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

Normally there are three different ways to do this:
at run time (via annotations per reflection)
at compile time (via annotations or aspects)
at development time (via code generators)
A good article to start is Clean Code in Android Applications.
Ad 1) Two solutions, see
RoboGuice, see http://code.google.com/p/roboguice/
AndJect, see https://github.com/ko5tik/andject
Ad 2) Android Annotations, see http://androidannotations.org/
Ad 3) Two solutions, see
the lazy-android plugin as mentioned in this thread, see http://marketplace.eclipse.org/content/lazy-android
MotoDev Studio (available as standalone and as eclipse plugin), see http://developer.motorola.com/docstools/motodevstudio/
If there is more, please tell!
I personally prefer 2) and therefore Android Annotations.
Hope that helps!

Use this online tool:
http://www.buzzingandroid.com/tools/android-layout-finder/
It simply gets the job done quickly. I use it every day.

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

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/

I use MotoDev Studio. It really saves time.

Related

Suggest code corrections in Idea

I've recently moved from Eclipse to Intellij IDEA for java development,
I have some code as shown in the screenshot, and as you can see there is no package called test2, Eclipse used to give suggestion if I want to create/move such a package, what is the IDEA equivalent shortcut for that option ?
Context specific actions can be brought up by alt+enter while having your cursor on the underlined part.
May I also suggest ctrl+shift+a. This brings up a search field for all kinds of menu items and settings.
Edit
Two more tips I always give IntelliJ newcomers:
Regularily check out Help/Productivity Guide. It tells you which features you don't use yet.
Install the Key promoter plugin. It tells you which shortcuts you could have used when you use an IntelliJ-Feature.

Android google repository - keyboard

guys, I'm looking for the source of the official android keyboard code but whenever I find in the official repositories, it is always with missing classes. I wonder where I can find the source (which is open), this terclado to be able to create and modify it and that works in versions 2.2 to the last.
I want to create an application where I can customize the layout with specific colors, etc. audio inputs and the like.
They could help me? I know it's maybe my question is not appropriate but do not give negative to block my account.
I just want to know where I can get the full source google Keyboard customize for me, but whenever I think, is missing classes at SRC.
thanks
Repos you can use
AnySoftKeyboard.git
LatinIME
A quick and concise google search is all you need to get what I just got. The first one is open source so it should be properly documented. The second one has a weird layout, but I don't use Google Source, so I wouldn't know how well it works/functions.

java files missing in scr folder in each Activity (eclipse)

Details: I have reinstalled eclipse 3 times, updated it & the ADT and DDMS, too.
I have found out that when I create a new android project the scr file is nearly empty. In each Activity there is only one java file and the rest is missing. I have attached a screenshot from the Maste/Detail flow activity so that you see where the problem is.
If you can help me please leave a response.
This is not a bug - it might generate additional files
depending on what starting activity you choose e.g. login activity it requires additional logic for working with Google+, however most will contain all the logic for a specific activity in a single source file, the source code included in the source files will often be minimal to make sure the activity works without the developer having to manually implement things they might otherwise not know about e.g. the fragment activity.
You might want to try out android studio instead if you are not dependent on eclipse as android seems to be moving towards using it and gradle.
(I do use android studios and am currently working on android apps and even though it's in beta it has not given me any problems)
This is a reported bug. Refer to https://code.google.com/p/android/issues/detail?id=72571
To solve the problem, look for ftl files in the tools\templates\activities subfolder of the SDK. In the files found, change <#if appCompat> to <#if appCompat?has_content>, and ${appCompat?string('Fragment','')} to ${(appCompat?has_content)?string('Fragment','')}.

Eclipse preference page with multiple arrays

I tried to search the internet for examples for doing that, but can not find a good one. Also I checking eclipse IDE source code, but it's a bit too big to filter out what I need for an example.
What I would need is something similar to Eclipse File Association page below.
My plan is later to replace File types list with a combo and add more values/controls per combo selection.
I would be very thankful for an example or a link to an example that does that or has a same concept with working preference store.
Thank you!
You can take a look at the Google Eclipse plugin source code. I had to achieve something similar to your needs, and inspired myself from there. It is properly designed. You can take a look at the repository right here.
In my case, I needed checkboxes instead of combos, and used a CheckboxTableViewer from the JFace library, there are plenty of example onlines (e.g: JFace snippets).
As Alex said, first, works on Eclipse preferences concept... when you got it, it will just stay some pure UI tasks.
Well, I think that it is nothing more then simple preferences page with two Lists which just represents conformity between file types and editors.
The example how to implement your own preferences page is here: Eclipse Preferences - Tutorial
If you want to have Combo - there is no problem - you just replace upper ListEditor woth your ComboFieldEditor and proceed with adding more conrols. The file associations are stored in Eclipse preferences and you can access them whenever you try to open some file to retrieve corresponding editor.

How to write an eclipse content assist?

I want to write a plugin which will give me content assist support and work in JSF. I want it to work like the sample below :
I'll type "p:button action="#{
Then I'll press "Ctrl+Shift+Space" (for example)
It'll read the classes in my project and show them as a list in a pop-up window
Then I'll select one class. It'll be like below
h:button action="#{MyClass
When I type "." , It'll read the methods in my selected class and show them as a list in a pop-up window.
Then I'll select a method
Finally, It'll end like this "h:button action="#{MyClass.MyMethod}
Do you have any idea, how can i do this? Any suggestions?
One place to look for an example of content assist is to look at XText which already has this feature for DSL-like languages.
See the XText sources in its Git repository: by looking work the log message 'assist', you will have a list of commits all related to content assist implementation, like the XbaseProposalProvider.java class.
The following are both screenshots from the Web Page Editor which comes with the Java EE edition of Eclipse.
You can install it by adding the following mirror to your Eclipse repository. Change the name depending on what version you use. For Helios it is http://download.eclipse.org/webtools/repository/helios.

Categories