riku
2020-08-21 0328eab9276e57487eb2cfff31a945a01dd8c73a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cn.flightfeather.thirdapp
 
 
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
 
/**
 * @author riku
 * 2019.3.29
 */
abstract class BaseFragment : Fragment() {
 
    protected var rootView: View? = null
    protected var inflater: LayoutInflater? = null
 
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        if (rootView != null) {
            val parentView = rootView?.parent as ViewGroup
            parentView.removeView(rootView)
        } else {
            rootView = inflater.inflate(getLayoutId(), container, false)
            this.inflater = inflater
            initView()
            initData()
        }
        return rootView
    }
 
    protected abstract fun getLayoutId(): Int
 
    protected abstract fun initView()
 
    protected abstract fun initData()
 
}