java - 为什么我的所有按钮都没有收到 android studio 中单击的输入?

标签 java android

我开发了一个管理一副纸牌的应用程序,我需要从这副纸牌中抽出 3 张牌。 问题是只有一个按钮可以点击并制作动画,但其他按钮没有收到点击事件。

//BUTTONS  
     private void setCardsForPlayer(){
        Giocatore giocatoreAttuale = banco.getGiocatoreAttuale();
      if(giocatoreAttuale.getCartaByIndex(0)!=null) {         
      buttonCard1.setImageDrawable(giocatoreAttuale.getCartaByIndex(0).
      getImmagine() );
           buttonCard1.setOnClickListener(new 
        CardHandler(this,giocatoreAttuale.getCartaByIndex(0)));
                }
       else{
          buttonCard1.setVisibility(View.INVISIBLE);
      }
      if(giocatoreAttuale.getCartaByIndex(1)!=null) {

    buttonCard2.setImageDrawable(giocatoreAttuale.getCartaByIndex(0). 
   getImmagine());
           buttonCard2.setOnClickListener(new 
      CardHandler(this,giocatoreAttuale.getCartaByIndex(1)));
      }
       else{
          buttonCard2.setVisibility(View.INVISIBLE);
      }
      if(giocatoreAttuale.getCartaByIndex(2)!=null) {

    buttonCard3.setImageDrawable(giocatoreAttuale.getCartaByIndex(2).
  getImmagine());
          buttonCard3.setOnClickListener(new 
 CardHandler(this,giocatoreAttuale.getCartaByIndex(2)));
      }
      else{
          buttonCard3.setVisibility(View.INVISIBLE);
     }
  }

//ANIMATIONS FUNCTION
private void muoviCarte(){
    Animation slideInAnimation = AnimationUtils.loadAnimation(this, 
 R.anim.move_cards); // THE ANIMATION
    buttonCard1.startAnimation(slideInAnimation);
    buttonCard2.startAnimation(slideInAnimation);
    buttonCard3.startAnimation(slideInAnimation);

}

最佳答案

那是因为您的按钮可能不在您的视野前面,导致它们不可点击。将其用于每个不可点击的按钮

yourButton.bringToFront();

关于java - 为什么我的所有按钮都没有收到 android studio 中单击的输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55853282/

相关文章:

java - 仅使用基元将元素动态添加到二维数组中

android - 文本颜色更改未反射(reflect)在 ListView 中

android - 寻找一种将步骤名称和场景写入文件的方法

java - servlet 和 HTML 表单之间的连接不起作用

Java 存储过程 UnsupportedClassVersionError

Java 打印服务 : PrintServiceLookup. lookupPrintServices 不返回网络打印机

android - 从手机的音频插孔记录数据

android - ActivityManagerProxy 中的 IllegalArgumentException

android - Android中ListView的分页

java - XML 文档的索引路径