3051ac22b265aab891cacf2ee17c924d6c6652a0.svn-base 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package com.example.myapplication.ui.slideshow;
  2. import android.os.Bundle;
  3. import android.view.LayoutInflater;
  4. import android.view.View;
  5. import android.view.ViewGroup;
  6. import android.widget.TextView;
  7. import androidx.annotation.Nullable;
  8. import androidx.annotation.NonNull;
  9. import androidx.fragment.app.Fragment;
  10. import androidx.lifecycle.Observer;
  11. import androidx.lifecycle.ViewModelProviders;
  12. import com.example.myapplication.R;
  13. public class SlideshowFragment extends Fragment {
  14. private SlideshowViewModel slideshowViewModel;
  15. public View onCreateView(@NonNull LayoutInflater inflater,
  16. ViewGroup container, Bundle savedInstanceState) {
  17. slideshowViewModel =
  18. ViewModelProviders.of(this).get(SlideshowViewModel.class);
  19. View root = inflater.inflate(R.layout.fragment_slideshow, container, false);
  20. final TextView textView = root.findViewById(R.id.text_slideshow);
  21. slideshowViewModel.getText().observe(this, new Observer<String>() {
  22. @Override
  23. public void onChanged(@Nullable String s) {
  24. textView.setText(s);
  25. }
  26. });
  27. return root;
  28. }
  29. }