java - Cast extended view to view layoutinflater -
java - Cast extended view to view layoutinflater -
what want able have own custom command have properties on it. i'm extending existing view (relativeview) , create own view. problem when seek relative view xml layout via inflater java lang class cast exeption. how can avoid ?
myrelativeview command = (myrelativeview) layoutinflater.from(getcontext()).inflate(r.layout.something, null, false);
myrelativeview extends relativelayout , inflated view relativelayout. why
java.lang.classcastexception: android.widget.relativelayout cannot cast controls.myrelativeview
your layout file should have custom view in it, view extends relativeview, relativeview not myrelativeview. should instead:
<com.example.customviews.myrelativeview xmlns:android="http://schemas.android.com/apk/res/android" custom:showtext="true" custom:labelposition="left" android:layout_width="match_parent" android:layout_height="match_parent" > <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:text="some text" android:paddingtop ="4dp" android:paddingbottom="4dp" android:id="@+id/textviewone" /> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:text="some text" android:paddingtop ="4dp" android:paddingbottom="4dp" android:id="@+id/textviewtwo" /> </com.example.customviews.myrelativeview>
java android android-layout
Comments
Post a Comment