android的代码规范

    xiaoxiao2023-03-24  3

    控件需要写在内部类中

    private class ViewHolder{ Button btn_add; Button btn_delete; Button btn_update; Button btn_query;}

    控件初始化要写在一个方法中,注意先将内部类实例化才能初始化控件

    public void init_view(){ holder = new ViewHolder(); holder.btn_add = findViewByIds(R.id.btn_add); holder.btn_delete = findViewByIds(R.id.btn_delete); holder.btn_update = findViewByIds(R.id.btn_update); holder.btn_query = findViewByIds(R.id.btn_query); }

    控件的事件也要写在方法中

    public void init_event(){ holder.btn_add.setOnClickListener(this); holder.btn_delete.setOnClickListener(this); holder.btn_update.setOnClickListener(this); holder.btn_query.setOnClickListener(this); }

    最后在onCreate中调用方法

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init_view(); init_event(); }

    转载请注明原文地址: https://ju.6miu.com/read-1201727.html
    最新回复(0)