Skip to content Skip to sidebar Skip to footer

How To Insert Custom View Into Xml's Linearlayout

So I have a CustomView which is extended from View. And I have a linear layout from XML. The XML named example:

Solution 1:

Your line should read:

gameView = (GameThread) Jembalang.this.findViewById(R.id.game_view);

you are passing the id of a layout rather than that of the view you have created.

The rest of your code looks fine

Solution 2:

I don't know what Jembalang is but I think you should remove that.

gameView = (GameThread) findViewById(R.id.game_view);

Solution 3:

You say your layout file is called "example.xml", but you call setContentView(R.layout.cobagabung). Thus, your view is initialized from "cobagabung.xml".

Make sure you use the same identifier for layout file name and setContentView call, like

setContentView(R.layout.example);

Post a Comment for "How To Insert Custom View Into Xml's Linearlayout"