findViewById 的偷懶方案,這函數名,哈哈。除了註解和在線生成,多了種偷懶方式

在微博中發現的偷懶方案,好簡單。。

//結果與(...)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!");


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章