简体   繁体   中英

How do I get back to my gl screen in android. I have tried to jump out and use an xml layout in my code

Ok I have looked everywhere on this site and have not found an answer to my question. I am trying to make a game and am at the point were I need to get the users information from the screen. I have my whole game done just need this part to move forward. I am going from a screen class to an xml layout and can't seem to get back to my screen class to move to the next part of the game. It seems easier to use the layout than to build the text boxes my self. Here is my code.

import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

import com.wright.knightsattack.framework.Game;
import com.wright.knightsattack.framework.gl.Camera2D;
import com.wright.knightsattack.framework.gl.SpriteBatcher;
import com.wright.knightsattack.framework.impl.GLScreen;
import com.wright.knightsattack.framework.math.Vector2;

public class NewCharacterInfo extends GLScreen
{
EditText Name, Strength, Dexterity, Agility, Intelligence, Charisma;
RadioButton Sex;
int intStrength, intDexterity, intAgility, intIntelligence, intCharisma;
Button Done_BTN;
Camera2D guiCam;
SpriteBatcher batcher;
Vector2 animPoint;
Game gameIn;
Activity activity;
Intent gameIntent;
Boolean enterInfo = true;

public NewCharacterInfo(Game game)
{
    super(game);
    gameIn = game;
    activity = (Activity) game;
}

@Override
public void resume()
{

}

@Override
public void update(float deltaTime)
{

    if (enterInfo == true)
    {
        runInfo();
    } else
    {

        newScreen();
        return;
    }
}

public void runInfo()
{
    activity.runOnUiThread(new Runnable()
    {
        public void run()
        {

            activity.setContentView(R.layout.new_character_info);

            Name = (EditText) activity.findViewById(R.id.editTextName);
            Sex = (RadioButton) activity.findViewById(R.id.radioButton1);
            Strength = (EditText) activity.findViewById (R.id.editTextStrength);
            Dexterity = (EditText) activity.findViewById(R.id.editTextDexterity);
            Agility = (EditText) activity.findViewById(R.id.editTextAgility);
            Intelligence = (EditText) activity.findViewById(R.id.editTextIntelligence);
            Charisma = (EditText) activity.findViewById(R.id.editTextCharisma);

            Done_BTN = (Button) activity.findViewById(R.id.done);
            Done_BTN.setOnClickListener(new OnClickListener()
            {
                public void onClick(View v)
                {
                    Log.e("Click check", "Inside");
                    if (v.getId() == R.id.done)
                    {
                        Log.e("Click check", "Try to change screen");
                        intStrength = Integer.parseInt(Strength.getText().toString());
                        intDexterity = Integer.parseInt(Dexterity.getText().toString());
                        intAgility = Integer.parseInt(Agility.getText().toString());
                        intIntelligence = Integer.parseInt(Intelligence.getText().toString());
                        intCharisma = Integer.parseInt(Charisma.getText().toString());
                        Settings.addCharacterStats(Name.getText().toString(), Sex.getText().toString(), 0, 0, 0, 0, 200, intStrength, intIntelligence, intDexterity, intAgility, intCharisma, 0, 0, 0, 0, 0, 0);

                        // gameIntent = activity.getIntent();
                        enterInfo = false;
                        update(0);
                        return;
                    }

                }
            });
        }

    });
}

public void newScreen()
{

    Settings.save(gameIn.getFileIO());
    gameIn.setScreen(new SplashHelmScreen(gameIn));
    Log.e("", "check" + gameIn);
    return;
}

@Override
public void present(float deltaTime)
{

}

@Override
public void pause()
{

}

@Override
public void dispose()
{

}
}

The xml screen will pop up, and I can enter information in all text boxs but when hit the done button it gives the error and here is the error I am getting from logcat.

01-09 11:04:38.038: E/libEGL(1743): call to OpenGL ES API with no current context (logged once per thread)

Thanks for any help I really appreciate it I have been strugling with this for a couple of days.

Nevermind, I fixed it, I just created a new intent and then when the information is entered I call finish() on the activity and it jumps to my current screen.

If you want to get back in the main screen you have two possibilities:

@Override
public void onBackPressed() {

}

or if you have a button:

Button btn =(Button)findViewById(R.id.btn); btn.setonClickListener(this);

@Override public void onClick(View v) {

    switch (v.getId()) {

case R.id.btn: kill_activity(); break;

}}

void kill_activity() {

finish();

}

Cheers,

Nevermind, I fixed it, I just created a new intent and then when the information is entered I call finish() on the activity and it jumps to my current screen.

public void newScreen()
{
    game = MainMenuScreen.globalGame;
    Settings.save(game.getFileIO());
    game.setScreen(new SplashHelmScreen(game));
    this.finish();
    Log.e("", "check" + game);
    return;
}

This jumps right back to my game. Sorry I answered this a long time ago, didn't realize I had to come down here and answer it. Thought the update took care of that. Thanks to all who tried to help!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM