Advertisement
Guest User

Untitled

a guest
May 6th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. open class MyBaseFragment : Fragment() {
  2. var rootView : View? = null
  3. var mActivity : Activity? = null
  4.  
  5. fun initView(inflater: LayoutInflater, container: ViewGroup?, resource :Int) : View?{
  6. if (rootView == null) {
  7. // Inflate the layout for this fragment
  8. mActivity = super<Fragment>.getActivity()
  9. rootView = inflater.inflate(resource, container, false);
  10. } else {
  11. // Do not inflate the layout again.
  12. // The returned View of onCreateView will be added into the fragment.
  13. // However it is not allowed to be added twice even if the parent is same.
  14. // So we must remove _rootView from the existing parent view group
  15. // (it will be added back).
  16. (rootView?.getParent() as ViewGroup?)?.removeView(rootView!!);
  17. }
  18. return rootView;
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement