cloudroam
2025-02-14 2fce91b8c0faf1290d8a35ee022dab3cdbc28a54
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.example.firstapp.ui.notifications
 
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.example.firstapp.databinding.FragmentNotificationsBinding
 
class NotificationsFragment : Fragment() {
 
    private var _binding: FragmentNotificationsBinding? = null
 
    // This property is only valid between onCreateView and
    // onDestroyView.
    private val binding get() = _binding!!
 
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val notificationsViewModel =
            ViewModelProvider(this).get(NotificationsViewModel::class.java)
 
        _binding = FragmentNotificationsBinding.inflate(inflater, container, false)
        val root: View = binding.root
 
        val textView: TextView = binding.textNotifications
        notificationsViewModel.text.observe(viewLifecycleOwner) {
            textView.text = it
        }
        return root
    }
 
    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}