277814c6a54e157d9e377bf815d0a26df3ca2229.svn-base 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package com.example.myapplication.ui.home;
  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 HomeFragment extends Fragment {
  14. private HomeViewModel homeViewModel;
  15. public View onCreateView(@NonNull LayoutInflater inflater,
  16. ViewGroup container, Bundle savedInstanceState) {
  17. homeViewModel =
  18. ViewModelProviders.of(this).get(HomeViewModel.class);
  19. View root = inflater.inflate(R.layout.fragment_home, container, false);
  20. final TextView textView = root.findViewById(R.id.text_home);
  21. homeViewModel.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. }