在微博中發現的偷懶方案,好簡單。。
//結果與(...)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!");