Featured post
android - Neither constructor nor onFinishInflate called for custom view -
i have custom view (which extends glsurfaceview) i'm trying use in app. xml layout uses appears being loaded correctly (attributes set view applied), neither view's constructor nor onfinishinflate method being called class. should add i'm new android platform stupid mistake.
here main.xml
<?xml version="1.0" encoding="utf-8"?>
#<!-- status bar --> <linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0" android:background="@drawable/status_bkg"> #<!-- location label --> <textview android:text="location" android:textcolor="#ffffff" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="wrap_content" /> #<!-- date/time label --> <textview android:text="date , time" android:textcolor="#ffffff" android:layout_weight="1" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right" /> </linearlayout> #<!-- chartview --> <view class="com.xxx.yyy.chartview" android:id="@+id/chartview" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00ff00" android:layout_weight="1"> </view>
the chartview custom glsurfaceview. layout loaded , chartview has green background specified. however, none of setup (in code) happens it. i've tried placing in 2 constructors , in onfinishinflate methods, inexplicably don't called. i've verified class name correct (the xxx.yyy hide company in post.
i've tried different form of xml reference
<com.xxx.yyy.chartview android:id="@+id/chartview" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00ff00" android:layout_weight="1"/>
but dies when loading activity says constructor
chartview(context context, attributeset attrs)
doesn't exist (although in code).
anyone got tips on going on?
i figured out. had defined constructor (the 1 not getting called) as:
public chartview( myactivity context, attributeset attrs ) { super( context, attrs ); …. }
however, started working when changed constructor be:
public chartview( context context, attributeset attrs ) { super( context, attrs ); …. }
given myactivity extends activity (which extends context), valid code , believe should work (it compiles). seem there error in reflection system using in locating method.
- Get link
- X
- Other Apps
Comments
Post a Comment