External XML as view

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

External XML as view

Postby Alexandro » Wed Mar 25, 2009 5:01 pm

Is it possible to use external view xmls to build an interface?

Here's what I was trying, but it gives me an InflateException

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.     public void onCreate(Bundle savedInstanceState) {
  3.  
  4.         super.onCreate(savedInstanceState);
  5.  
  6.         LayoutInflater inflater = getLayoutInflater();
  7.  
  8.         XmlPullParser parser=null;
  9.  
  10.         try {
  11.  
  12.                 XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
  13.  
  14.                 parser=factory.newPullParser();
  15.  
  16.                 // Utils just provides a layout xml as InputStream
  17.  
  18.                 Utils utils = new Utils(this);
  19.  
  20.                         parser.setInput(utils.getLayoutAsInputStream(), null);
  21.  
  22.                 } catch (XmlPullParserException e) {
  23.  
  24.                         // TODO Auto-generated catch block
  25.  
  26.                         e.printStackTrace();
  27.  
  28.                 } catch (IOException e) {
  29.  
  30.                         // TODO Auto-generated catch block
  31.  
  32.                         e.printStackTrace();
  33.  
  34.                 }
  35.  
  36.         inflater.inflate(parser, null);
  37.  
  38.     }
  39.  
  40.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


layout xml

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <RelativeLayout
  5.  
  6. android:id="@+id/widget29"
  7.  
  8. android:layout_width="fill_parent"
  9.  
  10. android:layout_height="fill_parent"
  11.  
  12. xmlns:android="http://schemas.android.com/apk/res/android"
  13.  
  14. >
  15.  
  16. <ImageView
  17.  
  18. android:id="@+id/widget73"
  19.  
  20. android:layout_width="wrap_content"
  21.  
  22. android:layout_height="wrap_content"
  23.  
  24. android:src="@drawable/boot_robot"
  25.  
  26. android:layout_centerVertical="true"
  27.  
  28. android:layout_centerHorizontal="true"
  29.  
  30. >
  31.  
  32. </ImageView>
  33.  
  34. <Button
  35.  
  36. android:id="@+id/widget33"
  37.  
  38. android:layout_width="150px"
  39.  
  40. android:layout_height="wrap_content"
  41.  
  42. android:text="Blue Pill"
  43.  
  44. android:layout_alignParentBottom="true"
  45.  
  46. android:layout_alignParentRight="true"
  47.  
  48. >
  49.  
  50. </Button>
  51.  
  52. <Button
  53.  
  54. android:id="@+id/widget32"
  55.  
  56. android:layout_width="150px"
  57.  
  58. android:layout_height="wrap_content"
  59.  
  60. android:text="Red Pill"
  61.  
  62. android:layout_alignParentBottom="true"
  63.  
  64. android:layout_alignParentLeft="true"
  65.  
  66. >
  67.  
  68. </Button>
  69.  
  70. </RelativeLayout>
  71.  
  72.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4
Alexandro
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Mar 05, 2009 5:42 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Google [Bot] and 8 guests