-
-
Save mobibob/d74d2e1ad9a08986dfb885371e27d096 to your computer and use it in GitHub Desktop.
kotlin deprecated ViewModelProviders (alternative)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DashboardFragment : Fragment() { | |
private lateinit var dashboardViewModel: DashboardViewModel | |
private var btnPodcast: Button? = null | |
override fun onCreateView( | |
inflater: LayoutInflater, | |
container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? { | |
// NOTE: The template Activity uses the deprecated ViewModelProviders constructor. | |
dashboardViewModel = ViewModelProvider.AndroidViewModelFactory(Application()).create(DashboardViewModel::class.java) | |
val root = inflater.inflate(R.layout.fragment_dashboard, container, false) | |
val textView: TextView = root.findViewById(R.id.text_dashboard) | |
dashboardViewModel.text.observe(viewLifecycleOwner, Observer { | |
textView.text = it | |
}) | |
return root | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment