抽取BaseActivity和BaseFragment

//抽取BaseActivity

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public abstract class BaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getView());
        initView();
        initData();
    }
//继承后这个里面写内容
    protected abstract void initData();
//这个里面写id
    protected abstract void initView();
这个里面写页面
    protected abstract int getView();
}

//抽取BaseFragment
package ningjiaxin1.bwie.com.lian.Base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public abstract class BaseFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(getViewLayout(),container,false);
    }
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        intiData();
    }
//继承后这个里面写内容
    protected abstract void intiData();
//继承后这个里面写id
    protected abstract void initView(View view);
//继承后这个里面写布局
    protected abstract int getViewLayout();
}

你可能感兴趣的:(抽取BaseActivity和BaseFragment)