Android: InflateException on composite component -


i'm creating pretty complex composite component throws inflateexception unknown cause. able replicate error in simplified version below, component 2 text views. in identifying error or tracking down appreciated.

composite_component.xml

<?xml version="1.0" encoding="utf-8"?> <com.cc.compositecomponent      xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content">     <textview         android:text="one"         android:layout_width="fill_parent"         android:layout_height="wrap_content"/>     <textview         android:text="two"         android:layout_width="fill_parent"         android:layout_height="wrap_content"/> </com.cc.compositecomponent> 

compositecomponent.java

package com.cc;  import android.app.activity; import android.content.context; import android.util.attributeset; import android.widget.linearlayout;  public class compositecomponent extends linearlayout {      public compositecomponent(context context) {     super(context);     }      public compositecomponent(context context, attributeset attributes){         super(context, attributes);     }      protected void onfinishinflate() {         super.onfinishinflate();         ((activity)getcontext()).getlayoutinflater().inflate(r.layout.composite_component, this);     } } 

compositeactivity.java

package com.cc;  import android.app.activity; import android.os.bundle;  public class compositeactivity extends activity {      public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.composite_component);     } } 

androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.cc"     android:versioncode="1"     android:versionname="1.0"> <uses-sdk android:minsdkversion="8" />  <application android:icon="@drawable/icon" android:label="compositecomponent">     <activity android:name="compositeactivity"               android:label="compositecomponent">         <intent-filter>             <action android:name="android.intent.action.main" />             <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>  </application> 


in composite_component.xml file, try changing line:

<com.cc.compositecomponent 

to following:

<linearlayout 

and then, create second layout activity passes setcontentview():

file: composite_activity_layout.xml

<com.cc.compositecomponent     android:id="@+id/my_composite"     <!-- other stuff ->> 

file: compositeactivity.java

protected void oncreate( bundle state ) {     super.oncreate( state );      setcontentview(r.layout.composite_activity_layout);     // ... } 

what looks doing causing recursive layout inflation. inflate compositecomponent, , in onfinishinflate() method, compositecomponent inflates copy of itself.

also, may want investigate use of android's merge tag avoid having linearlayout hanging around.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -