Dynamic UI element generation - What is possible, what not ?

  • Replies:6
  • OpenNot stickiedUnanswered
  • Forum posts: 13

Aug 8, 2013 10:27:21 AM via Website

Hello in here.
I am really new in this forum and would like to say : Nice job.
keep on, this forum seems to be seems the right place for many enthusiastic android developers ( also for me, for example, as a beginner ) and also professionals.

I read some tutorials and created useless apps with the adt, emulated on the bluestacks .
This was for "getting started with android and java".

But now I must really do something, and this is far away from all tutorials, which I have found.

Lets go into detail:

Status now :
There is a database with
- metadata about "how much activities a special application has".
- metadata about which ui-elements reside on each activity, with location, size, backcolor, forecolor ,fontstyle, etc
- metadata, which button click could cause navigation to another screen, leaving a ) parent screen for ever or b) possibility of returning to it

I must write a runtime ui generator in order to make it available under android.
The runtime generator parses the metadata from the database tables and tries to apply them on each ui-element.

I have sample codes in other languages, but I was googling and read about some things, which appeared not to be so simple under android.

So, in general I would like to know, what of the following points is possible/impossible in android development:

- create forms ( activities ) at runtime
- create ui-elements ( buttons, textviews, etc. ) at runtime and assign them to the correct activity ( form )
- changing properties of ui elements at runtime
- switching forth and back among activities.

Each information is welcome.

Deactivated Account
  • Forum posts: 131

Aug 13, 2013 10:20:51 AM via Website


Instead of Activities, maybe you might want to look at Fragments.
It's very easy to add and remove Fragments in runtime with the FragmentManager.

It's also very easy to change the layout of a Fragment at runtime.
You just create the layout you want, for example LinearLayout, put everything you want inside, and make the createView() method from the Fragment return that View you created.

Play a little bit with Fragments, it should work.
  • Forum posts: 13

Aug 13, 2013 11:02:08 AM via Website

Hi, Henrique,

THX for Your answer, You are always welcome.

So, will it be possible to navigate to another "form" ( activity ) from one by pressing any button with the help of fragments and even back ?

As I read, I can create fragments as "small containers" on one activity so I partition one activity.

Do You mean, I can use "one main activity" and "put N dummy containers" on it, where all other elements ( buttons, Labels, Checkboxes, Progressbars, and so on ) can be placed at runtime ?
  • Forum posts: 2

Aug 20, 2013 2:37:43 AM via Website

Hi there,

You may want to give Metawidget (http metawidget dot org) a look. It is an Android View that generates UI components at runtime based on metadata. It's very pluggable and configurable, and is fully Open Source. So even if Metawidget itself is not right for your needs, you may find it useful to look at the source code to see how it works.

There is a complete tutorial and Android sample application included in the documentation and download.

Disclaimer: I'm the author. If you give Metawidget a try and have any feedback, I'd love to hear from you!



P.S. Please don't confuse Metawidget with Meta Widget, which is an Android App that lets you display metadata feeds (like stock tickers) on your phone's background. It's a great project, but nothing to do with Metawidget!
  • Forum posts: 13

Aug 20, 2013 8:18:46 AM via Website

Thx very much.

I will take a look.

Most important is the support of android 2.3 because I use the bluestacks emulator, which is very good but has some restrictions regarding os version.

So, I will check it out tomorrow or already this evening.

See ya.
  • Forum posts: 13

Aug 20, 2013 8:25:09 AM via Website

So, then I will have a short look already now :-)