You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PageViewModel.java 743B

1234567891011121314151617181920212223242526
  1. package com.example.meinwald.ui.main;
  2. import androidx.arch.core.util.Function;
  3. import androidx.lifecycle.LiveData;
  4. import androidx.lifecycle.MutableLiveData;
  5. import androidx.lifecycle.Transformations;
  6. import androidx.lifecycle.ViewModel;
  7. public class PageViewModel extends ViewModel {
  8. private MutableLiveData<Integer> mIndex = new MutableLiveData<>();
  9. private LiveData<String> mText = Transformations.map(mIndex, new Function<Integer, String>() {
  10. @Override
  11. public String apply(Integer input) {
  12. return "Hello world from section: " + input;
  13. }
  14. });
  15. public void setIndex(int index) {
  16. mIndex.setValue(index);
  17. }
  18. public LiveData<String> getText() {
  19. return mText;
  20. }
  21. }