Android的按钮仅在第二次点击工作 [英] android button only working at second time click

查看:148
本文介绍了Android的按钮仅在第二次点击工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发Android游戏,奇怪的是,在我的游戏的主菜单按钮只有工作,他们被点击的第二次。我已经试图把onClick的按钮XML文件(并在活动​​视图属性中的公众法),但我得到了同样的结果。谁能帮我?

这是XML:

 <按钮
        机器人:ID =@ + ID / botaoTeppo
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_below =@ + ID / versaoDoJogo
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_centerVertical =真
        机器人:layout_marginTop =40dp
        机器人:背景=@绘制/ botao_menu_principal
        机器人:paddingLeft =10dp
        机器人:paddingRight =10dp
        机器人:文字=@字符串/ botaoTreino
        机器人:TEXTSIZE =40SP
        机器人:文字颜色=#FFFFFF/>

和这里的的onCreate(),用于将buttonListener:

  @覆盖
公共无效的onCreate(捆绑savedInstanceState){
    。super.getGameHelper()setMaxAutoSignInAttempts(0);
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
    switchToScreen(R.id.tela_inicial_sumo_sensei);    字符串fontpathChines =字体/ Wonton.ttf
    字体tfChines = Typeface.createFromAsset(getAssets(),fontpathChines);
    按钮botaoTeppo =(按钮)findViewById(R.id.botaoTeppo);
    按钮botaoJogarOnline =(按钮)findViewById(R.id.botaoJogarOnline);
    按钮botaoModoCompeticao =(按钮)findViewById(R.id.botaoModoCompeticao);
    botaoTeppo.setTypeface(tfChines);
    botaoJogarOnline.setTypeface(tfChines);
    botaoModoCompeticao.setTypeface(tfChines);    botaoTeppo.setOnClickListener(新OnClickListener(){        @覆盖
        公共无效的onClick(视图v){            Toast.makeText(getApplicationContext(),波涛红外PRA铁炮acionado,Toast.LENGTH_SHORT).show();
            ArmazenaMostrarRegrasTreinamento mostrarExplicacaoDoTeppoAntes = ArmazenaMostrarRegrasTreinamento.getInstance();
            布尔mostrarExplicacaoDoTeppo = mostrarExplicacaoDoTeppoAntes.getMostrarRegrasDoTreinamento(getApplicationContext());
            意图iniciaTelaTreinoIndividual;
            如果(mostrarExplicacaoDoTeppo ==真)
            {
                iniciaTelaTreinoIndividual =新意图(MainActivity.this,ExplicacaoTeppo.class);
            }
            其他
            {
                iniciaTelaTreinoIndividual =新意图(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 =新ChecaVersaoAtualDoSistemaTask(这一点,this.popupCarregandoSeUsuarioEstahNaVersaoAtual);
    taskChecaVersaoAtualDoSistema.execute();
}


解决方案

我有同样的问题与我公司开发的自定义相机的应用程序。

如果您在本次活动采用全屏布局,尽量把这个code在AndroidManifest.xml文件所需的活动之下:

 <活动
            机器人:名字=。YOUR_ACTIVITY
            机器人:configChanges =方向
            机器人:标签=@字符串/ title_activity_YOUR_ACTIVITY
            机器人:主题=@安卓风格/ Theme.NoTitleBar.Fullscreen>

这确实神奇的线是:机器人:主题=@安卓风格/ Theme.NoTitleBar.Fullscreen

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

解决方案

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"

这篇关于Android的按钮仅在第二次点击工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆