gpt4 book ai didi

android - 我如何在 android 中返回到我的 gl 屏幕。我曾尝试跳出并在我的代码中使用 xml 布局

转载 作者:太空狗 更新时间:2023-10-29 14:23:47 26 4
gpt4 key购买 nike

好吧,我在这个网站上到处都看了,但没有找到我的问题的答案。我正在尝试制作游戏,此时我需要从屏幕上获取用户信息。我已经完成了整个游戏,只需要这部分就可以继续前进。我正从屏幕类转到 xml 布局,似乎无法回到我的屏幕类以移动到游戏的下一部分。使用布局似乎比我自己构建文本框更容易。这是我的代码。

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()
{

}
}

将弹出 xml 屏幕,我可以在所有文本框中输入信息,但是当点击完成按钮时出现错误,这是我从 logcat 得到的错误。

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

感谢您的帮助,我真的很感激我已经为此苦苦挣扎了几天。

没关系,我修复了它,我只是创建了一个新的 Intent ,然后当输入信息时,我在 Activity 上调用 finish() 并跳转到我的当前屏幕。

最佳答案

如果您想返回主屏幕,您有两种选择:

@Override
public void onBackPressed() {

或者如果你有一个按钮:

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

@覆盖 public void onClick(View v) {

    switch (v.getId()) {

案例 R.id.btn: kill_activity();休息;

}}

void kill_activity(){

完成();

干杯,

关于android - 我如何在 android 中返回到我的 gl 屏幕。我曾尝试跳出并在我的代码中使用 xml 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14241602/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com