在微博中发现的偷懒方案,好简单。。
//结果与(...)findViewById(R.id....)一模一样,采用$作为方法名称,借鉴自jQuery
public <T extends View> T $(int id) {
return (T)super.findViewById(id);
}
用法
private EditText editor;
editor = $(R.id.p_name);
editor.setText("Hello World!");
在微博中发现的偷懒方案,好简单。。
//结果与(...)findViewById(R.id....)一模一样,采用$作为方法名称,借鉴自jQuery
public <T extends View> T $(int id) {
return (T)super.findViewById(id);
}
private EditText editor;
editor = $(R.id.p_name);
editor.setText("Hello World!");