Android User Interface Code is Not Easily Reusable

I’m ideally looking for someone to correct or enlighten me here, so please do!

The basic premise I want to put forward is that user interface components and libraries developed for the Android platform are not as easily reusable as standard Java Swing-based UIs. As opposed to simply linking a JAR file as you would in a J2SE or J2ME application, an Android developer must deal with the following files:

  • An XML layout definition
  • An entry in the R.java resource file
  • The class definition(s)

It isn’t just the variety of files, but the process of integrating the third-party code into your application in a clean way that I am concerned with.

Am I missing something here? Is there an easy to just import a JAR into your lib, and load all of this up at once, possibly referencing a resource file and a separate set of layout XMLs within that JAR?

Maybe I need to go back and re-read the Building Custom Components section of the Android Developer Guide. Hmm.

2 comments

  1. You do not have to use XML. All you can do in XML and more you can do in Java code on Android. Therefore you are welcome to write your own UI components and reuse them as you would in any real Java application.

    However. You have to use android API and you can not use Java2D or Swing because it is not available in Dalvik.

  2. Wow, that is a really old post (2008!), and very early in my time working on Android. You are absolutely right of course, and to be honest, I don’t care much about portability of Android UI these days.

    Thanks for the response however!

Leave a comment