vinay Maneti vinay Maneti - 4 months ago 99
Android Question

Create a Dynamic UI in Android from json Template

On the App start, I will download the data from the web-server and store it in shared-preference, now what I want is depending upon the json template dynamically create the UI form/Activity in android.Can any one suggest me how to implement this.

"label":"Your e-mail",


XML layouts are converted to Java objects at runtime, so you can simply write an XML which has a container Layout ( say Linear Layout ), inflate it at runtime, and add view programatically depending on the information received from server.

An example would be :
Creating a layout, and setting that as the Activity's content view.

<LinearLayout xmlns:android=""

Then somewhere in code:
Let's say that after parsing the JSON you have a List<Field> fields;

  LinearLayout linearLayout = (LinearLayout) findViewById(;
  for (Field f: fields) {
    if (f.getType().equals("textbox")) {
        TextView txtView = new TextView(this);
        txtView.setText("Your e-mail");
        txtView.setId(1);//need for better use
    } else if (f.getType().equals("button")) {
        //create a button similarly as above,and add it to the layout