Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open class MyBaseFragment : Fragment() {
- var rootView : View? = null
- var mActivity : Activity? = null
- fun initView(inflater: LayoutInflater, container: ViewGroup?, resource :Int) : View?{
- if (rootView == null) {
- // Inflate the layout for this fragment
- mActivity = super<Fragment>.getActivity()
- rootView = inflater.inflate(resource, container, false);
- } else {
- // Do not inflate the layout again.
- // The returned View of onCreateView will be added into the fragment.
- // However it is not allowed to be added twice even if the parent is same.
- // So we must remove _rootView from the existing parent view group
- // (it will be added back).
- (rootView?.getParent() as ViewGroup?)?.removeView(rootView!!);
- }
- return rootView;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement