1
爲什麼我只看到「第一」烤麪包,而不是從我的線程創建的其他人(應該)?活動忽略顯示從我的線程執行Toast
public class BannerExample extends Activity {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Toast toast = Toast.makeText(this, "first toast", Toast.LENGTH_SHORT);
toast.show();
new MyThread(this).start();
}
class MyThread extends Thread {
private Context context;
public MyThread(Context context) {
this.context = context;
}
public void run() {
Looper.prepare(); // An exception told me to add this - i have no clue why
for (int i = 0; i < 3; i++) {
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Toast toast = Toast.makeText(context, i + "whoho", Toast.LENGTH_SHORT);
toast.show();
}
}
}
}
真棒,謝謝! – corgrath 2011-03-27 21:09:31