1 つの MainActivity があります。この Main に SurfaceView を表示したいのですが、ボタンがクリックされた場合のみです。そのため、メインが開始され、ユーザーが 1 つのボタンをクリックすると、SurfaceView が表示され、表示されるたびに onCreate-Method が実行されます。
しかし、うまくいきませんでした。
私のコードはすべてこのコンストラクターにあります。
public GameView(Context context, AttributeSet attrs)
したがって、これは使用する必要がありますが、何をすべきかわかりません:/
編集:
XML のコード:
<de.apex.viewer.view.GameView
android:id="@+id/gameView1"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerInParent="true"
android:layout_marginLeft="94dp" />
メインのコードは次のとおりです。
public void displayGameView(View view)
{ // here I need code to "recreate" my gameView
}
そして、ここに表示されるべき GameView からのいくつかのコード:
public class GameView extends SurfaceView {
public GameView(Context context, AttributeSet attrs)
{
super(context, attrs);
surfaceHolder = getHolder();
surfaceHolder.addCallback(new SurfaceHolder.Callback()
{
public void surfaceDestroyed(SurfaceHolder holder)
{}
public void surfaceCreated(SurfaceHolder holder)
{
// here is my code I want to execute
Canvas theCanvas = surfaceHolder.lockCanvas(null);
HouseInRow = DefineRowCount(arraylength);
GesamtZahl = HouseInRow*2+HouseInColumn*2;
System.out.println("Houserow: " + HouseInRow);
public void surfaceChanged(SurfaceHolder holder, int format,int width, int height)
{}
});
}