文章目录
只为积攒一点工具类,用的时候方便
1. 替换findViewById
//正常方法
protected <T> T $(int resId) {
T t = (T) findViewById(resId);
return t;
}
//直接带注册点击事件方法
protected <T> T $(int resId, View.OnClickListener l) {
T t = (T) findViewById(resId);
if (t instanceof Button) {
((Button) t).setOnClickListener(l);
}
if (t instanceof TextView) {
((TextView) t).setOnClickListener(l);
}
return t;
}
//--使用
textview = $(R.id.textview);
button = $(R.id.button, this);