java - findViewById crashing when using a custom view with <merge> and <include> tags -
i trying make custom view using xml retrieve properties , edit them. custom view added test2 view several times different id's each. have tried retrieve id 1 of these custom views (player_1) textview (player_name), , edits properties , no other views player_2 id view.
but not sure this possible? renders fine, error every time try in code. i'm not sure how approach this, can't seem inflate work either test instead. ideas?
thanks!
game.java
setcontentview(r.layout.test2); view player1 = (view) findviewbyid(r.id.player_1); textview player1name = (textview) player1.findviewbyid(r.id.player_name); player1name.settext("john"); test2.xml
<include layout="@layout/player_view" android:id="@+id/player_1" /> <include layout="@layout/player_view" android:id="@+id/player_2" /> player_view.xml
<?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/android" xmlns:player="http://schemas.android.com/apk/res/com.example.android.merge"> <linearlayout android:id="@+id/top_view" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" > <textview android:id="@+id/player_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="textview" > </textview> </linearlayout> </merge> this cut down version of player_view.xml, can post more if needed.
also have not worked out if prints error message in eclipse, goes debug mode , not explain further issue is.
your player_view.xml has unknown type, include confused kind of view it. try next: use or create new playerview class, mergeable player_view.xml.
edit test2.xml to:
<playerview android:id="@+id/player_1" /> <playerview android:id="@+id/player_2" /> then inflate in code following:
setcontentview(r.layout.test2); playerview player1 = (playerview) findviewbyid(r.id.player_1); layoutinflater inflate = (layoutinflater) getcontext().getsystemservice(context.layout_inflater_service); inflate.inflate(r.layout.player_view, player1); do same player2.
Comments
Post a Comment