fragment

How to access parent Activity View in Fragment

落花浮王杯 提交于 2020-08-20 18:26:42
问题 I have an ActionBarActivity and fragment. I am using FragmentPagerAdapter that provides fragment to my app. My question How can I access parent Activity View in Fragment ?? 回答1: You can use View view = getActivity().findViewById(R.id.viewid); Quoting docs Specifically, the fragment can access the Activity instance with getActivity() and easily perform tasks such as find a view in the activity layout 回答2: At first, create a view like this: View view = getActivity().findViewById(R.id.viewid);

ViewModelProviders is not working inside my Fragment

◇◆丶佛笑我妖孽 提交于 2020-08-06 12:47:07
问题 This is what I'm trying to do. Set an ArrayList of object inside a Fragment Get that array from an observer within the FragmentActivity container (the activity that hosts all the fragments) So, What I have done is the following. First I created the SharedViewModel from where I will set and get the data from : SharedViewModel.kt class SharedViewModel: ViewModel() { var personArrayObj:MutableLiveData<ArrayList<Person>> = MutableLiveData() fun setPersonArray(personArray:ArrayList<Person>){