Android button only works the second time
I am developing an Android game and, oddly enough, in the main menu of the game, the buttons only work the second time they are pressed. I've already tried putting onClick in the button button file (and public method with view attribute in Activity), but I got the same result. Can anyone help me?
this is XML:
<Button
android:id="@+id/botaoTeppo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/versaoDoJogo"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="40dp"
android:background="@drawable/botao_menu_principal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/botaoTreino"
android:textSize="40sp"
android:textColor="#FFFFFF" />
and here's onCreate () to add a buttonListener:
@Override
public void onCreate(Bundle savedInstanceState) {
super.getGameHelper().setMaxAutoSignInAttempts(0);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
switchToScreen(R.id.tela_inicial_sumo_sensei);
String fontpathChines = "fonts/Wonton.ttf";
Typeface tfChines = Typeface.createFromAsset(getAssets(), fontpathChines);
Button botaoTeppo = (Button)findViewById(R.id.botaoTeppo);
Button botaoJogarOnline = (Button) findViewById(R.id.botaoJogarOnline);
Button botaoModoCompeticao = (Button) findViewById(R.id.botaoModoCompeticao);
botaoTeppo.setTypeface(tfChines);
botaoJogarOnline.setTypeface(tfChines);
botaoModoCompeticao.setTypeface(tfChines);
botaoTeppo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "botão ir pra teppo acionado", Toast.LENGTH_SHORT).show();
ArmazenaMostrarRegrasTreinamento mostrarExplicacaoDoTeppoAntes = ArmazenaMostrarRegrasTreinamento.getInstance();
boolean mostrarExplicacaoDoTeppo = mostrarExplicacaoDoTeppoAntes.getMostrarRegrasDoTreinamento(getApplicationContext());
Intent iniciaTelaTreinoIndividual;
if(mostrarExplicacaoDoTeppo == true)
{
iniciaTelaTreinoIndividual = new Intent(MainActivity.this, ExplicacaoTeppo.class);
}
else
{
iniciaTelaTreinoIndividual = new Intent(MainActivity.this, EscolhaNivelActivity.class);
}
startActivity(iniciaTelaTreinoIndividual);
}
});
this.popupCarregandoSeUsuarioEstahNaVersaoAtual =
ProgressDialog.show(MainActivity.this, getResources().getString(R.string.checando_versao_atual),
getResources().getString(R.string.por_favor_aguarde));
ChecaVersaoAtualDoSistemaTask taskChecaVersaoAtualDoSistema = new ChecaVersaoAtualDoSistemaTask(this, this.popupCarregandoSeUsuarioEstahNaVersaoAtual);
taskChecaVersaoAtualDoSistema.execute("");
}
0
source to share
2 answers
I had the same problem with an app where I developed a custom camera.
If you are using a full screen layout in this exercise, try to place this code in your AndroidManifest.xml file under the activity you want:
<activity
android:name=".YOUR_ACTIVITY"
android:configChanges="orientation"
android:label="@string/title_activity_YOUR_ACTIVITY"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
The line that does the magic: android: theme = "@android: style / Theme.NoTitleBar.Fullscreen"
0
source to share