Android_BaseFragment의 정의

1219 단어
/**
 * Author:DoctorWei
 * Time:2018/11/3 11:16
 * Description: Fragment
 * email:[email protected]
 */

public abstract class BaseFragment extends Fragment {
    private BaseActivity mActivity;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mActivity= (BaseActivity) context;
    }
    @Override
    public void onDetach() {
        super.onDetach();
        mActivity=null;
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(getLayoutId(),container,false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        init(view);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData(savedInstanceState);
    }
    protected abstract int getLayoutId();

    protected abstract void init(View view);

    protected abstract void initData(Bundle savedInstanceState);

좋은 웹페이지 즐겨찾기