[英]Code seems to stop xml layout from showing in Android Studio
The problem is that I have an Android app that doesn't seem to show the xml layout when I put this while loop into the class file. 问题是当我将while循环放入类文件时,我有一个Android应用程序似乎没有显示xml布局。 The loop is as follows:
循环如下:
while(!clicked){
button_a.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
player= MediaPlayer.create(GameActivity.this, R.raw.a);
player.start();
clicked = true;
letterTapped = 0;
}
});
}
The whole project works completely fine without it so I'm pretty sure that there must be something wrong with the loop that I am overlooking. 没有它,整个项目就可以正常工作,所以我很确定我忽略的循环一定有问题。 If you want me to put any other bits of code up here I will be more than happy to.
如果您希望我在此处添加其他代码,我将非常高兴。
To stop listening as soon as the button is pressed, you can use this code: 要在按下按钮后立即停止收听,您可以使用以下代码:
button_a.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
player= MediaPlayer.create(GameActivity.this, R.raw.a);
player.start();
letterTapped = 0;
// Ignore further clicks
button_a.setOnClickListener(null);
// Disable button so the user knows that he can't click again
button_a.setEnabled(false);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.