Skip to content

Commit

Permalink
Add sample with inflate for DialogFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
kirich1409 committed Oct 21, 2020
1 parent 8274d6c commit e13eff3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@file:Suppress("unused")

package by.kirich1409.viewbindingdelegate.sample.reflection.inflate

import android.app.Dialog
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import by.kirich1409.viewbindingdelegate.CreateMethod
import by.kirich1409.viewbindingdelegate.dialogViewBinding
import by.kirich1409.viewbindingdelegate.sample.R
import by.kirich1409.viewbindingdelegate.sample.databinding.FragmentProfileBinding
import by.kirich1409.viewbindingdelegate.viewBinding

class ProfileDialogFragment1 : DialogFragment() {

private val viewBinding: FragmentProfileBinding by viewBinding(createMethod = CreateMethod.INFLATE)

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return AlertDialog.Builder(requireContext())
.setView(viewBinding.root)
.create()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@file:Suppress("unused")

package by.kirich1409.viewbindingdelegate.sample.reflection.inflate

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import by.kirich1409.viewbindingdelegate.CreateMethod
import by.kirich1409.viewbindingdelegate.viewBinding
import by.kirich1409.viewbindingdelegate.dialogViewBinding
import by.kirich1409.viewbindingdelegate.sample.R
import by.kirich1409.viewbindingdelegate.sample.databinding.FragmentProfileBinding

class ProfileDialogFragment2 : DialogFragment() {

private val viewBindingUsingReflection: FragmentProfileBinding by viewBinding(createMethod = CreateMethod.INFLATE)

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return viewBindingUsingReflection.root
}
}

0 comments on commit e13eff3

Please sign in to comment.