我想让随机字符在按钮中切换,直到您按下停止按钮。当您按下停止按钮时,随机字符将显示为按钮文本。我设法做到这一点的唯一方法是使用线程。但是我有问题,它工作了 3-4 次,但是当我第三次或第四次打开活动时,应用程序崩溃了。我不知道为什么会这样。我需要帮助来解决这个问题。如果有人知道一些没有线程的方法并想提供帮助,我将不胜感激。
这是应用程序的图片:点击
public class NajduzaRec extends AppCompatActivity {
private int brojac = 0;
String randomLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//char[] randomLetters = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'V', 'Z', 'Ž', 'Č', 'Ć', 'Đ', 'Š'};
private boolean threadRunning=true;
Random r = new Random();
private static ManualResetEvent mre = new ManualResetEvent(false);
EditText unosReciTxt;
Button stopBtn, slovo1Btn,slovo2Btn,slovo3Btn,slovo4Btn,slovo5Btn,slovo6Btn,slovo7Btn,slovo8Btn,slovo9Btn,slovo10Btn,slovo11Btn,slovo12Btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_najduza_rec);
stopBtn = (Button)findViewById(R.id.stopBtn);
slovo1Btn = (Button)findViewById(R.id.slovo1Btn);
slovo2Btn = (Button)findViewById(R.id.slovo2Btn);
slovo3Btn = (Button)findViewById(R.id.slovo3Btn);
slovo4Btn = (Button)findViewById(R.id.slovo4Btn);
slovo5Btn = (Button)findViewById(R.id.slovo5Btn);
slovo6Btn = (Button)findViewById(R.id.slovo6Btn);
slovo7Btn = (Button)findViewById(R.id.slovo7Btn);
slovo8Btn = (Button)findViewById(R.id.slovo8Btn);
slovo9Btn = (Button)findViewById(R.id.slovo9Btn);
slovo10Btn = (Button)findViewById(R.id.slovo10Btn);
slovo11Btn = (Button)findViewById(R.id.slovo11Btn);
slovo12Btn = (Button)findViewById(R.id.slovo12Btn);
unosReciTxt = (EditText)findViewById(R.id.unosReciTxt);
/*while(brojac==0) {
char randomChar = randomLetters.charAt(r.nextInt(randomLetters.length()));
slovo1Btn.setText("" + randomChar);
}*/
皈依舞
烙印99
守着一只汪
随时随地看视频慕课网APP
相关分类