我試圖做到這一點@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); t=new TextView(this); t=(TextView)findViewById(R.id.TextView01); t.setText("Step One: blast egg"); try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } t.setText("Step Two: fry egg");但是由于某種原因,我運行它時只顯示第二個文本。我認為這可能與Thread.sleep()方法阻塞有關。那么有人可以告訴我如何“異步”實現計時器嗎?
3 回答

慕哥9229398
TA貢獻1877條經驗 獲得超6個贊
我剛剛在Android討論Google組中發布了此答案
如果您只是想向視圖中添加文本,以使其顯示為“步驟1:炸雞蛋步驟2:油炸雞蛋”,請考慮使用t.appendText("Step Two: fry egg");
而不是t.setText("Step Two: fry egg");
如果您想完全更改其中的內容,以TextView
使其在啟動時顯示“第一步:炸雞蛋”,然后每次顯示“第二步:炸雞蛋”,則可以始終使用
Sadboy給的可運行的例子
- 3 回答
- 0 關注
- 1537 瀏覽
添加回答
舉報
0/150
提交
取消