| | |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.TextView; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.annotation.Nullable; |
| | | import androidx.fragment.app.Fragment; |
| | | import androidx.lifecycle.Observer; |
| | | import androidx.lifecycle.ViewModelProvider; |
| | | import com.duqing.missions.R; |
| | | |
| | | import com.duqing.missions.databinding.FragmentNotificationsBinding; |
| | | |
| | | public class NotificationsFragment extends Fragment { |
| | | |
| | | private NotificationsViewModel notificationsViewModel; |
| | | private FragmentNotificationsBinding binding; |
| | | private FragmentNotificationsBinding binding; |
| | | |
| | | public View onCreateView(@NonNull LayoutInflater inflater, |
| | | ViewGroup container, Bundle savedInstanceState) { |
| | | notificationsViewModel = |
| | | new ViewModelProvider(this).get(NotificationsViewModel.class); |
| | | |
| | | binding = FragmentNotificationsBinding.inflate(inflater, container, false); |
| | | View root = binding.getRoot(); |
| | | |
| | | final TextView textView = binding.textNotifications; |
| | | public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| | | notificationsViewModel = new ViewModelProvider(this).get(NotificationsViewModel.class); |
| | | binding = FragmentNotificationsBinding.inflate(inflater, container, false); |
| | | View root = binding.getRoot(); |
| | | notificationsViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() { |
| | | @Override |
| | | public void onChanged(@Nullable String s) { |
| | | textView.setText(s); |
| | | } |
| | | }); |
| | | return root; |
| | | } |
| | | |
| | | @Override |
| | | @Override |
| | | public void onDestroyView() { |
| | | super.onDestroyView(); |
| | | binding = null; |
| | | } |
| | | |
| | | } |