android静态代理(findViewById)

本文详细探讨了在Android开发中如何使用静态代理提高findViewById的效率,通过实例解析其工作原理,并给出最佳实践建议。
摘要由CSDN通过智能技术生成
package com.huangxudong.bindview;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * 编译时注解
 *
 * <p>主要用来对编译class文件的时候生成代理类</p>
 *
 * <p>减少findViewbyId次数,提高编码效率</p>
 *
 * @Target {@code 注解所适用的地方,这里写的是类字段 {@link Target}}
 *
 * @Retention {@code 注解所应用的时机,这里是在编译class文件的时候}
 *
 * @author Mr Huang 2018/7/7
 *
 * @version 1.0
 */

@Target(ElementType.FIELD)

@Retention(RetentionPolicy.CLASS)

public @interface BindView {

    /**
     * 注解的参数,这里主要是为了确定控件id的
     *
     * @return id
     */
    int value();


}
package com.huangxudong.bindview;

import javax.lang.model.element.VariableElement;

/**
 * 代理类需要关联处理的属性
 *
 * <p>主要是用来对控件与控件的id进行关联,并提供给代理类</p>
 *
 * @author Mr Huang 2018/7/7
 *
 * @version 1.0
 */
public class VariableInfo {

    /**
     * 控件id
     */
    private int varId;

    /**
     * 控件对象,也就是在内存中存在的对象
     */
    private VariableElement mVariableElement;

    public int getVarId() {
        return varId;
    }

    public void setVarId(int varId) {
        this.varId = varId;
    }

    p
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值