BaseFragment

public abstract class BaseFragment

extends Fragment implements View.OnClickListener { public View mView = null; //当前布局View 可用来寻找View中的控件 protected static Context mActivity; protected P mPresenter; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { if (mView == null) { mPresenter = createPresenter(); mView = inflater.inflate(layout(), container, false); mActivity = getActivity(); initView(); } else { ViewGroup viewGroup = (ViewGroup) mView.getParent(); if (viewGroup != null) { viewGroup.removeView(mView); } } return mView; } protected abstract int layout(); protected abstract P createPresenter(); protected abstract void initView(); protected abstract void setOnClike(View v); @Override public void onClick(View v) { setOnClike(v); } public void openNewActivity(Class clas) { startActivity(new Intent(getActivity(), clas)); } public void ToastUtils(String str) { Toast.makeText(ConsulAppLication.getContext(), str, Toast.LENGTH_SHORT).show(); } @Override public void onDestroy() { super.onDestroy(); if (mPresenter != null) { mActivity = null; mPresenter.detachView(); mPresenter = null; } } }

你可能感兴趣的:(Android,Base)