Activity的基類+Fragment的基類
阿新 • • 發佈:2018-11-30
1.Activity的基類
public abstract class BaseActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(LoadLayout()); initView(); initdata(); } public abstract int LoadLayout(); //檢視 public abstract void initView(); //獲取id的資料 public abstract void initdata(); }
2.Fragment的基類
public abstract class BaceFragment extends Fragment { @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(getLayout(),container,false); } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); initView(view); } public abstract int getLayout(); //獲取資源ID public abstract void initView(View view); @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); initdata(); } public abstract void initdata(); }