gpt4 book ai didi

java - 暂时禁用 Action 监听器

转载 作者:太空宇宙 更新时间:2023-11-04 09:04:22 26 4
gpt4 key购买 nike

我是 Android Studio 的新手。我有个问题。我正在制作比赛卡应用程序。比赛失败后,卡片会在 0.5 秒后翻转回来。不过此时,你仍然可以检查其他卡。我想禁用它。我将 Button 扩展到一个类。我正在发布这两个脚本。感谢您的帮助。

这是我的卡片类。

public class kart extends Button {
boolean acikMi = false;
boolean cevrilebilir = true;
int arkaPlanID;
int onPlanID=0;
Drawable on;
Drawable d;

public kart(Context context, int id) {
super(context);
setId(id);
arkaPlanID = R.drawable.arka1;
if(id%8==1)
onPlanID = R.drawable.c1;
if(id%8==2)
onPlanID = R.drawable.c2;
if(id%8==3)
onPlanID = R.drawable.c3;
if(id%8==4)
onPlanID = R.drawable.c4;
if(id%8==5)
onPlanID = R.drawable.c5;
if(id%8==6)
onPlanID = R.drawable.c6;
if(id%8==7)
onPlanID = R.drawable.c7;
if(id%8==0)
onPlanID = R.drawable.c8;
d = AppCompatDrawableManager.get().getDrawable(context,arkaPlanID);
on = AppCompatDrawableManager.get().getDrawable(context, onPlanID);
setBackground(d);


}
public void cevir(){
if (cevrilebilir){
if(!acikMi){
setBackground(on);
acikMi = true;
}
else{
setBackground(d);
acikMi=false;
}

}

}

这是我的 Java 代码。

    public class GameScreen extends AppCompatActivity {
int sonKart = 0;
int skor = 0;
int hamle;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_screen);
Intent i = getIntent();
final String s = i.getStringExtra("ad");
TextView tv = (TextView) findViewById(R.id.textView);
tv.setText(s);
GridLayout gr = (GridLayout) findViewById(R.id.grid);
kart kartlar[] = new kart[16];
for (int j = 1; j <= 16; j++) {
kartlar[j - 1] = new kart(this, j);
kartlar[j-1].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hamle++;
final kart k = (kart)v;
k.cevir();
if (sonKart >0){
final kart k2 = (kart) findViewById(sonKart);
if (k2.onPlanID==k.onPlanID&&k2.getId()!=k.getId()){
k2.cevrilebilir=false;
k.cevrilebilir=false;
sonKart =0;
skor++;
TextView tv = (TextView) findViewById(R.id.textView3);
TextView tv2 = (TextView) findViewById(R.id.textView5);
tv.setText("Score: "+skor);
tv2.setText("Total moves: "+hamle);
if (skor==8){
Intent i = new Intent(GameScreen.this,scoreboard.class);
i.putExtra("ham",hamle);
i.putExtra("isim",s);
startActivity(i);
//oyun bitti

}



}
else{

Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
k2.cevir();
k.cevir();

}
},500);
sonKart =0;
TextView tv2 = (TextView) findViewById(R.id.textView5);
tv2.setText("Total moves: "+hamle);

}
}
else{
sonKart = k.getId();
}

}
});
}

for (int j=0;j<16;j++){
int rg =(int) (Math.random()*16);
kart k = kartlar[rg];
kartlar[rg] = kartlar [j];
kartlar[j] = k;
}

for (int j = 0; j < 16; j++)
gr.addView(kartlar[j]);




}
}

最佳答案

禁用点击按钮

      button.setEnabled(false);

关于java - 暂时禁用 Action 监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60413167/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com