android按钮仅在第二次点击时工作

时间:2015-02-13 14:45:12

标签: android button

我正在开发一款Android游戏,奇怪的是,在我的游戏主菜单中,这些按钮仅在第二次点击时才会工作。我已经尝试将onClick放在按钮XML文件中(以及Activity中带有视图属性的公共方法),但我得到了相同的结果。任何人都可以帮助我吗?

这是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" />

这里是用于添加buttonListener的onCreate():

@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("");
}

2 个答案:

答案 0 :(得分:2)

将此行添加到xml中的按钮并尝试:

  

机器人:可聚焦= “假”

答案 1 :(得分:0)

我在开发自定义相机的应用程序时遇到了同样的问题。

如果您在此活动中使用全屏布局,请尝试将此代码放在您需要的活动下的AndroidManifest.xml文件中:

<activity
            android:name=".YOUR_ACTIVITY"
            android:configChanges="orientation"
            android:label="@string/title_activity_YOUR_ACTIVITY"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

行神奇的是:android:theme =&#34; @android:style / Theme.NoTitleBar.Fullscreen&#34;