好的,我在这个网站上到处查看,但没有找到我的问题的答案。我正在尝试制作游戏,并且我需要从屏幕上获取用户信息。我已经完成了整个游戏,只需要这一部分继续前进。我正在从屏幕类转到 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)
感谢您的帮助,我真的很感激我已经为此苦苦挣扎了几天。
没关系,我修复了它,我刚刚创建了一个新意图,然后当输入信息时,我在 Activity 上调用 finish() 并跳转到我当前的屏幕。