2011年8月13日 星期六

[Dialog] Showing a Dialog

onCreateDialog(int)

  • 若是在 Activity 中 override this method,或是替 dialog 設setOwnerActivity(Activity),那麼 Activity 便會自動負責管理此 dialog,否則則不會。
  • 在 showDialog(int) 時,僅有在第一次會呼叫 onCreateDialog(int),因此必須在此建立欲回傳的 dialog,之後再呼叫便都是回傳此 dialog 而不會再呼叫此 method 產生。
  • but...this is deprecated should using DialogFragment (since API Level 11)。


onPrepareDialog(int, Dialog)

  • 每次顯示 dialog 時,此 method 都會被呼叫,因此若想使用同個 dialog 但又必須更換其中的資料,可在此 method 中設定,若沒設定則每次呼叫同個 Id 的 dialog 都會顯示相同的內容。



* Reference
- Creating Dialogs | Android Developers

沒有留言:

張貼留言