android button only working at second time click

I am developing an android game and, strangely, in my game's main menu the buttons only work the second time they are clicked. I already tried putting the onClick in the button XML file(and the public method with the view atribute in the Activity), but I got the same result. Can anyone help me?

this is the 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 the onCreate() for adding the 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("");
}

Upvotes: 1

Views: 1709

Answers (2)

Shailendra Madda
Shailendra Madda

Reputation: 21531

Add this line to button in xml and try:

android:focusable="false"

Upvotes: 4

Victor Viola
Victor Viola

Reputation: 585

I had the same issue with an application which I developed a custom camera.

If you are using a fullscreen layout in this activity, try to put this code in your AndroidManifest.xml file under the activity you need:

<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 is: android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

Upvotes: 0

Related Questions