abstract class BaseFragment : Fragment(){ companion object{ var popupWindow : PopupWindow ?= null } var dialog : ProgressDialog ?= null override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { var view : View = inflater.inflate(getInitId(),container,false) initView(view) initData() initAdapter() initLinstener() //初始化屏幕适配 AutoUtils.auto(view) return view; } //显示加载圈 fun showLoading(){ if(dialog!!.isShowing){ return } dialog = ProgressDialog(activity) dialog!!.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog!!.setCanceledOnTouchOutside(false) dialog!!.setProgressStyle(ProgressDialog.STYLE_SPINNER) dialog!!.setMessage("正在加载") dialog!!.show() } fun dismissLoading(){ if(dialog!!.isShowing){ dialog!!.dismiss() } } abstract fun initLinstener() abstract fun initAdapter() abstract fun initData() abstract fun initView(view: View) abstract fun getInitId() : Int override fun onDestroy() { super.onDestroy() if(dialog !!.isShowing){ dialog!!.dismiss() } } }
kotlin版BaseFragment
最新推荐文章于 2024-06-24 16:59:48 发布