Android Layout Finder online tool

Hi guys, hope you had a great new years!

If you’ve ever developed an Android app, you’ve probably used the findViewById() method for finding views and findFragmentById() for finding fragments from your inflated layout. This has to be done with every View and Fragment that you want to access from your code.

After getting tired of writing the same code over and over again, I created a tool to generate that code for me from an arbitrary XML layout:

Behold: The Android Layout Finder!

You can try it out on a sample XML layout by pressing the ‘Paste example XML’ button in the right side of the screen.

Android Layout Finder is open source and licensed under the GNU General Public License. The code can be found on GitHub: http://www.github.com/jesperborgstrup/android-layout-finder. Enjoy!

About the author

Jesper Borgstrup Jesper is a Masters student of computer science at the University of Copenhagen with many years of experience in writing applications for Android.

15 thoughts on “Android Layout Finder online tool

  1. Mike

    Hey, I love your layout finder. It’s great. It’d be even greater if you could add a feature so that when there is a button/imagebutton it adds setOnClickListener(this) and the onClick(View arg) with the switch case inside for all the ids of the buttons/imagebuttons on the Activity! That would be neat and would save a lot of fiddling!
    Thanks again!

    Reply
    1. Jesper Borgstrup Post author

      This is actually a great idea. I have just implemented this for the “Member variables” code type. The option is enabled by default, and can be disabled by unchecking the “Implement ClickListeners for Buttons and ImageButtons” option.
      Thank you for your input :-)

      Reply
  2. Riddhish

    Awesome tool. I’ve started using your tool to generate the boilerplate code. It saves time. Thanks.

    Reply
  3. Naveed

    This is exactly what I was looking for, real time saver.
    suggestions: There should be ability to put onlicklistener to other views like edittext and textview, plus It would be great if tool allow user to select views he want onclicklistener.

    Great thanks for this cool tool

    Reply
  4. AndroidAnnotationsFan

    I love your tool but I use androidannotations. It’s almost the sama as RoboGuice but instead of @InjectView androidannotations library uses @ViewById. It will be simple to implement and very helpful. Great job!

    Reply
  5. Julio

    Thank you very much for this tool ! It’s really usefull.
    I have the same suggestion than the previous comment. I use some ImageViews and TextViews which I need to config their onClickListeners. It would be nice to add this to these views as well.
    Thanks!

    Reply
  6. Felixqk

    Nice tool! It would be nicer if it can handle “include” tag in XML and generate the Java code for the elements in included XML.

    Keep on good work!

    Reply
  7. MaxiMax

    Nice tool! =)

    For ArrayAdapter with ViewHolder you can make your code easier. =))


    viewHolder = ViewHolder.create((RelativeLayout) convertView);

    replace to:


    viewHolder = new ViewHolder((RelativeLayout) convertView);

    class ViewHolder should be similar to this:


    private static class ViewHolder {

    public final TextView field;

    private ViewHolder(RelativeLayout rootView) {
    field = (TextView) rootView.findViewById(R.id.field);
    }
    }

    It would be nice if you did. Thank you for your service! =)

    Reply
  8. Adeeb

    Thank you so much for your effort
    this tool is just what I wanted !
    I think it would be super awesome if you can exclude a prefix from the id as many people name their id’s with a prefix for each XML file.

    Keep the GREAT work !

    Cheers.

    Reply
    1. Jesper Borgstrup Post author

      Hello, and thank you for your comment.

      I have added the feature (“Remove ID prefix” in General settings)
      Hope you like it!

      Cheers

      Reply
    1. Jesper Borgstrup Post author

      Hi, I think that the code is pretty similar to the RoboGuice code that is already supported.
      If there are any differences, please ley me know so I can try to implement it as well.

      Reply
  9. Pingback: آزمایشگاه تمرین – پیدا کردن محتویات لی اوت بصورت اتوماتیک

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>