Create a Dynamic UI in Android from json Template
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="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id="@+id/container" />
Then somewhere in code:
Let's say that after parsing the JSON you have a List<Field> fields;
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.container); 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 linearLayout.addView(txtView); } else if (f.getType().equals("button")) { //create a button similarly as above,and add it to the layout } }
I think you’re asking about Server Driven UI, please go through this link to know more about it:https://proandroiddev.com/dynamic-screens-using-server-driven-ui-in-android-262f1e7875c1