baseActivity的封装——模板式设计模式

news/2024/7/6 0:20:40
public abstract class BaseActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //初始化布局
        setContentView();
        // 一些特定的算法,子类基本都会使用的(比如butterknife注解等)
        ViewUtils.inject(this);
        //初始化头部
        initTitle();
        //初始化界面
        initView();
        //初始化数据
        initData();
    }

    //初始化数据
    protected abstract void initData();

    //初始化界面
    protected abstract void initView();


    //初始化头部
    protected abstract void initTitle();

    // 设置布局layout
    protected abstract void setContentView();

    /**
     * 启动activity
     */
    protected void startActivity(Class<?> clazz) {
        Intent intent = new Intent(this, clazz);
        startActivity(intent);
    }
    /**
     * findviewbyld进行封装
     */
    protected <T extends View> T findviewByld(@IdRes int viewld){
        return (T) findViewById(viewld);
    }


}

http://www.niftyadmin.cn/n/3648856.html

相关文章

使用Visual Studio Code和ESLint进行保存

We need style guides to write consistent, reusable and clean code. But when you have been working 10 hours a day on a project for the past 3 months it’s hard to notice an extra indentation in your code or a single quote instead of a double quote. 我们需要…

Git使用教程详解之一 Git起步

起步 本章介绍开始使用 Git 前的相关知识。我们会先了解一些版本控制工具的历史背景&#xff0c;然后试着让 Git 在你的系统上跑起来&#xff0c;直到最后配置好&#xff0c;可以正常开始开发工作。读完本章&#xff0c;你就会明白为什么 Git 会如此流行&#xff0c;为什么你应…

网络引擎与数据库相结合

结合之前两篇文章链式调用打造第三方的网络引擎 http://blog.csdn.net/qq_24675479/article/details/79277616 和 自己动手搭建数据库框架 http://blog.csdn.net/qq_24675479/article/details/79285849 首先逻辑处理:每次都会请求数据&#xff0c;但是为了保证用户体验&…

css伪类选择器_如何使用CSS:root伪类选择器

css伪类选择器Learn about the CSS :root pseudo-class selector, and how you might want to use it in your projects! 了解CSS :root伪类选择器&#xff0c;以及如何在项目中使用它&#xff01; The CSS :root pseudo-class selector is used to select the highest-level …

Git使用教程详解之二 Git基础

Git 基础 读完本章你就能上手使用 Git 了。本章将介绍几个最基本的&#xff0c;也是最常用的 Git 命令&#xff0c;以后绝大多数时间里用到的也就是这几个命令。读完本章&#xff0c;你就能初始化一个新的代码仓库&#xff0c;做一些适当配置&#xff1b;开始或停止跟踪某些文件…

自定义view——实现评分控件RatingBar的实现

首先看下效果图 星星是两个不同的图片 首先老套路&#xff1a;自定义属性 <?xml version"1.0" encoding"utf-8"?> <resources><declare-styleable name"RatingBar"><attr name"starNormal" format"ref…

[C#][固定格式网页解析]使用正则表达式处理网页的初步体会

用IE WebControl解析网页得到特定网页中的特定数据&#xff1a;Set oDocument Form2.m_IE.Document Set oelement oDocument.Forms("searchdetail") Set oListTableElement oelement.children(0).children(0)这样的好处是简单&#xff0c;但坏处是&…

如何在Ubuntu 18.04上使用Apache设置密码身份验证[快速入门]

介绍 (Introduction) This tutorial will walk you through password-protecting assets on an Apache web server running on Ubuntu 18.04. Completing these steps will provide your server with additional security so that unauthorized users cannot access certain pa…