The DialogFragment class provides all the controls you need to create your dialog and manage its appearance, instead of calling methods on the Dialog object.
The DialogFragment class was originally added with Android 3.0 (API level 11), for older API this class is provided with the Support Library.
if use support library version & proguard,
-keep class android.support.v4.app.** { *; } -keep interface android.support.v4.app.** { *; }should be added to proguard rule.
Create NumberPickerDialogFragment
Override onCreateDialog() method.
the returned Dialog will be shown when NumberPickDialogFragment instance call show() method.
for example in Activiry
when click "Show Number Picker Dialog"
Create NumberPicker
set NumberPickDialogFragment view with NumberPicker
now Dialog will be shown like this
Create Interface
Selected value will be handled by Activity that made the Dialog, so declare interface to pass the value.
this interface called when "OK" & "Cancel" clicked.
implement in Activity
when Show Number Pick Dialog button clicked |
When OK clicked show text 100 |
Complete code
MainActivity.javaNumberPcikDialogFragment.java
댓글
댓글 쓰기