[問題] callback中修改UI

看板AndroidDev作者 (.)時間13年前 (2012/06/03 23:48), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
private Camera.PictureCallback jpegCallback = new Camera.PictureCallback(){ public void onPictureTaken (byte[] data, Camera camera) { ((TextView)findViewById( R.id.save_file)).setText("a"); ((TextView)findViewById( R.id.save_file)).requestLayout(); try { Thread.sleep(1000); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String path = "/sdcard/DCIM/xxxx.jpg"; File file = new File(path); try{ file.createNewFile(); OutputStream os2 = new BufferedOutputStream(new FileOutputStream(file),8192); os2.write(data); os2.close(); ((TextView)findViewById( R.id.save_file)).setText("b"); } catch ( IOException e ){ } synchronized(semaphore) { semaphore.notify(); } } }; 簡單來說問題就是 永遠只看得到 .setText("b"); 的顯示 .setText("a"); 永遠看不到 已經使用過一些看起來像是強制刷新UI的方法來更新 結果似乎永遠只會顯示最後檔案寫入完畢後的 .setText("b"); 請問這個該怎麼處理呢? -- ※ 編輯: erspicu 來自: 111.184.195.252 (06/03 23:49)

06/07 01:00, , 1F
setText("a")寫在函數外?
06/07 01:00, 1F
文章代碼(AID): #1FouTgij (AndroidDev)
文章代碼(AID): #1FouTgij (AndroidDev)