So I have a CustomView
which is extended from View
. And I have a linear layout from XML.
The XML named example
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/jembalang.comfest.game"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<jembalang.compfest.game.GameThread
android:id="@+id/game_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</jembalang.compfest.game.GameThread>
<Button
android:text="Button"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
And the code using the xml
setContentView(R.layout.cobagabung);
gameView = (GameThread) Jembalang.this.findViewById(R.id.game_view);
gameView.setFocusable(true);
gameView.setFocusableInTouchMode(
gameView.start();
I added the GameThread constructor if that's helping
public class GameThread extends View implements Runnable,OnKeyListener{
public GameThread(Context context,AttributeSet attr){
super(context, attr);
...
}
public GameThread(Context context) {
super(context);
...
}
I think there is something wrong with my way doing it, because the findViewById
returns null
How should I do to make my CustomView
(GameThread
at this example) to be able inserted into xml?