-
Notifications
You must be signed in to change notification settings - Fork 410
Example
olfek edited this page Sep 2, 2018
·
1 revision
This example is in Kotlin
. IntelliJ (and Android Studio) should automatically convert it for you into Java
when copying and pasting.
Create a class which extends DialogFragment
like so:
import android.content.Context
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.appeaser.sublimepickerlibrary.SublimePicker
import com.appeaser.sublimepickerlibrary.datepicker.SelectedDate
import com.appeaser.sublimepickerlibrary.helpers.SublimeListenerAdapter
import com.appeaser.sublimepickerlibrary.helpers.SublimeOptions
import com.appeaser.sublimepickerlibrary.recurrencepicker.SublimeRecurrencePicker
class SublimePickerDialogFragment : DialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
var mListener = object : SublimeListenerAdapter() {
override fun onCancelled() {
// Handle click on `Cancel` button
}
override fun onDateTimeRecurrenceSet(sublimeMaterialPicker: SublimePicker?, selectedDate: SelectedDate?, hourOfDay: Int, minute: Int, recurrenceOption: SublimeRecurrencePicker.RecurrenceOption?, recurrenceRule: String?) {
recurrenceRule?.let{
// Do something with recurrenceRule
}
recurrenceOption?.let {
// Do something with recurrenceOption
// Call to recurrenceOption.toString() to get recurrenceOption as a String
}
}
}
var sublimePicker = SublimePicker(context)
var sublimeOptions = SublimeOptions() // This is optional
sublimeOptions.setPickerToShow(SublimeOptions.Picker.REPEAT_OPTION_PICKER) // I want the recurrence picker to show.
sublimeOptions.setDisplayOptions(SublimeOptions.ACTIVATE_RECURRENCE_PICKER) // I only want the recurrence picker, not the date/time pickers.
sublimePicker.initializePicker(sublimeOptions,mListener)
return sublimePicker
}
}
Then, in an Activity
. Do the following:
val fragmentManager = supportFragmentManager
var sublimePickerDialogFragment = SublimePickerDialogFragment()
var bundle = Bundle()
// put arguments into bundle
sublimePickerDialogFragment.arguments = bundle
sublimePickerDialogFragment.isCancelable = false
sublimePickerDialogFragment.show(fragmentManager,null)
Then just use the dismiss()
function on/in the instance of the DialogFragment
to close/dismiss it.
Your welcome :)