This will not be possible with what your asking. Android relies on Resource identifiers using a class call R which is automatically generated. The file contains public static final int
references for various class values in your application. The classes referenced here can be found at http://developer.android.com/reference/android/R.html
This class is than used to reference the various resources in your application, one of which is layout
. So the system expects all layouts defined in xml to be included in this generated R
class.
So in one sentence: you will not be able to accomplish this the way you want.
What i would do is have a json response and convert it to dynamically generated layout.
for XML you download test.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<TextView android:id="@+id/textViewTest"
android:layout_centerInParent="true"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</RelativeLayout>
If you want to have this layout created in your app create a json response:
{
"layout_parent":"RelativeLayout",
"layout_height": "match_parent",
"layout_width": "match_parent",
"layout_children": [
{
"layout_child":"TextView",
"layout_child_id":"textViewTest",
"layout_height":"wrap_content",
"layout_width":"match_parent",
"layout_gravity":"center",
"layout_centerInParent":"true"
}
]
}
i would then parse this to a model object and use that model object to build your layouts dynamically. In order to add the fields though you will need to have some layout you defined in xml to be able to add more fields to in your app.