Skip to content

Instantly share code, notes, and snippets.

@Bambina-zz
Last active July 22, 2017 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bambina-zz/bd67d578044e830ee00943b0e43145e7 to your computer and use it in GitHub Desktop.
Save Bambina-zz/bd67d578044e830ee00943b0e43145e7 to your computer and use it in GitHub Desktop.
public class SharedViewModel extends ViewModel {}
public class MasterFragment extends Fragment {
    private SharedViewModel model;
    public void onCreate(Bundle savedInstanceState) {
        model = ViewModelProviders.of(getActivity())
.get(SharedViewModel.class); //<- 共通のviewmodel
    }
}
public class DetailFragment extends LifecycleFragment {
    public void onCreate(Bundle savedInstanceState) {
        SharedViewModel model = ViewModelProviders.of(getActivity())
.get(SharedViewModel.class); //<- 共通のviewmodel
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment