【发布时间】:2023-03-20 23:48:01
【问题描述】:
what is wrong with following code.
做一些事情说 words.lenght=1000 次
然后假设用户想在两者之间休息
单击 id = bt 的暂停按钮此按钮暂停线程,直到用户单击 id= bt1 的恢复
Runnable myRun = new Runnable(){
public void run(){
for(int j =0 ;j<=words.length;j++){
synchronized(this){
try {
wait(sleepTime);
bt.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}});
bt2.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
notify();
}
});
} catch (InterruptedException e) {
e.printStackTrace();
} }
runOnUiThread(new Runnable(){
public void run(){
try {
et.setText(words[i]);
i++;
} catch (Exception e) {
e.printStackTrace();
}
}});
}}};
【问题讨论】:
-
代码中是否有任何错误或正在询问您的方法。
-
@fahad 我在问方法
标签: android multithreading runnable synchronized