Note that there are some explanatory texts on larger screens.

plurals
  1. POSurfaceView and adding and deleting other views
    text
    copied!<p>I am trying to create a simple game based on the 2D game framework as described in the 2011 Apress book, "Beginning Android Games" by Mario Zechner. Maybe that helps, maybe it doesn't, but either way:</p> <p>I only have one activity for the whole game. Everything is rendered onto a bitmap, which is then sent to a SurfaceView, and what is sent to the SurfaceView will change based on what screen the game is on.</p> <p>I want to implement a simple highscore system that lets users enter their name into an EditView on the main menu screen. I've been able to combine the SurfaceView and the EditView with a RelativeLayout, but the problem is getting rid of the EditView once the user moves past the main menu screen.</p> <p>There is much more to this class, but here's a snipet of what I feel is important:</p> <pre><code> public abstract class AndroidGame extends Activity implements Game{ public EditText et; public RelativeLayout rl; public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); et = new EditText(this); renderView = new AndroidFastRenderView(this, frameBuffer); rl = new RelativeLayout(this); rl.addView(renderView); rl.addView(et); setContentView(rl); } } </code></pre> <p>The above is the only activity for the game. The AndroidFastRenderView class extends SurfaceView. The problem I'm having is that while I need the SurfaceView to persist through the whole game, I need EditText to only persist for a short while, then disappear based on touch events.</p> <p>I try to call RelativeLayout.removeView(et) from my class MainMenuScreen, which is responsible for constructing the bitmap sent to the SurfaceView as well as listening for touch events. But I get an uncaught exception that says I can't edit views that are defined in one thread from another.</p> <p>I'm sorry for the novel, but I've been trying to solve this myself for hours with no luck. I feel like this is a very simple thing I'm just not getting. Any help is much appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload