Skip to content

Commit

Permalink
UI has to be declared in onCreateView not in onCreate
Browse files Browse the repository at this point in the history
  • Loading branch information
justdave committed May 20, 2024
1 parent 306bfb6 commit a1cfd00
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.justdave.nwsweatheralertswidget

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -18,18 +19,16 @@ import net.justdave.nwsweatheralertswidget.objects.NWSZone
class DebugFragment : Fragment() {

private lateinit var viewModel: DebugViewModel
private lateinit var binding: DebugFragmentBinding
private var _binding: DebugFragmentBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = DebugFragmentBinding.inflate(inflater, container, false)
return binding.root
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.i("AlertsDisplayFragment", "onCreateView called")
_binding = DebugFragmentBinding.inflate(inflater, container, false)
viewModel = ViewModelProvider(this)[DebugViewModel::class.java]
viewModel.initializeContext(requireActivity().applicationContext)
lifecycleScope.launch {
Expand Down Expand Up @@ -110,6 +109,13 @@ class DebugFragment : Fragment() {
// foo
}
}
val view = binding.root
return view
}

override fun onDestroyView() {
_binding = null
super.onDestroyView()
}

}

0 comments on commit a1cfd00

Please sign in to comment.