Thursday, 15 July 2010

android - Change activity's layout by an XML string contained in main memory in runtime -


I have an activity that is displayed to the user. On the activity, I have a button every time the user pushes the button, the app will load an XML file from a remote server. The XML file is actually a layout designed for the application. After the new XML file is loaded and corrected in the new layout variable, I am showing the user who would like to set the XML file to replace the current layout.

  string newLayoutStr = ""; OnClickButton () {newLayoutStr = loadNewLayoutFromRemoteServer ();  

any comment

with this you ask Will not be possible. Android depends on resource identifiers which uses class call R which is generated automatically. The file contains the public static final int reference for different square values ​​of your code. Here can be found in the referenced sections

This class is going to be used in the context of various resources in your application, one of these is layout . Therefore, all the layouts defined in XML are expected to be included in the generated code in the R category.

So in one sentence: You will not be able to fulfill the way you want.

What I will do is a Jason reaction and it has changed into a dynamically-generated layout.

For XML, you download test.xml

  & lt; ? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; RelativeLayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_height = "match_parent" android: layout_width = "match_parent" & gt; & Lt; TextView android: id = "@ + id / textViewTest" Android: layout_centerInparent = "true" Android: gravity = "center" Android: layout_height = "wrap_content" Android: layout_width = "match_parent" /> & Lt; / RelativeLayout & gt;  

If you want to create a layout created in your app, then create Jason Reaction:

  {"layout_parent": "Relative layout", "layout_heart" "Layout_width": "match_parent", "layout_children": [{"layout_children": "textviewview", "layout_child_id": "textvivestest", "layout_hete": "wrap-content", "layout_width": " Then, I will parse a model object and use that model object as your "match_part", "Layout_gravity": "center", "layout_centerInParent": "true"}]}  

To make the layout dynamically. To add the field you will need some layout defined in XML to be able to add more fields to your app.


No comments:

Post a Comment