Вот решение для вашего кода:
Код для DialogFragment
class ListFragment: DialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val rootView = inflater.inflate(R.layout.list_layout, container)
var pioneers = arrayOf("Jon Snow", "Mother of Dragon-Khalessi", "Ned Stark", "Benjen Stark", "Cathlyen Stark", "Arya Stark", "Sansa Stark", "Littelfiger", "Jamie Lannister")
val myListView = rootView.findViewById(R.id.myListView) as ListView
myListView!!.adapter = ArrayAdapter<String>(activity, android.R.layout.simple_list_item_1, pioneers)
this.dialog.setTitle("Game Of Thrones")
myListView.setOnItemClickListener {
adapterView,
view,
position,
l
-> Toast.makeText(activity, pioneers[position], Toast.LENGTH_SHORT).show()
}
return rootView
}
}
In your activity you can make call something like this
val openFragmentBtn = findViewById<Button>(R.id.openFragmentID)
//On button Click Open Dialog Fragment
val openFragmentBtn = findViewById(R.id.openFragmentID) as Button
val fm = supportFragmentManager
val listFragment= ListFragment()
openFragmentBtn.setOnClickListener(object : View.OnClickListener {
override fun onClick(view: View) {
listFragment.show(fm, "PioneersFragment_tag")
}
})
Попробуйте это
val pop = alarm_first()
val fm = this@YourActivityName.fragmentManager
pop.show(fm, "name")
Я реализовал этокод для учебной цели, но если он вам подходит, я с радостью помогу