Nour Medhat
Nour Medhat

Reputation: 617

I want to show DialogFragment in Android using Kotlin

I want to show DialogFragment when button is clicked but I have error in my code the error is in fun " show "

this my code " button on click "

DialogFragment

val pop = alarm_first()
val fm = FragmentManager
pop.show( fm , "name")

and this my fragment class for "alarm_first" :

class alarm_first : DialogFragment() {
override fun onCreateView(inflater: LayoutInflater?, container: 
 ViewGroup?, savedInstanceState: Bundle?): View {

    var myView = inflater!!.inflate(R.layout.fragment_alarm_first
            , container, false)

    return myView
}}

Upvotes: 0

Views: 15749

Answers (4)

suraj bokankar
suraj bokankar

Reputation: 11

We can use DialogFragment to show the content which we need to represent in boundary of your Activity which will work like a enhancement to current feature.

I have achieved this by doing following,

val fragment = DemoFragment()   
fragment.show(childFragmentManager,"DemoFragment")

childFragmentManager = getChildFragmentManager() of java

tag = "Name Of Fragment".

Upvotes: 0

Ganesh Anbarasu
Ganesh Anbarasu

Reputation: 21

Try this...

val fm = supportFragmentManager

Upvotes: 2

user4696837
user4696837

Reputation:

Edit this part

val pop = alarm_first()
val fm = FragmentManager
pop.show(fm, "name")

To

val pop = alarm_first()
val fm = [email protected]
pop.show(fm, "name")

Upvotes: 3

Pravin Londhe
Pravin Londhe

Reputation: 895

Replace

val fm = FragmentManager

with

val fm = fragmentManager

Upvotes: 1

Related Questions