通过泛型来简化findViewById

我们一般写findViewById都要加个强制转换,感觉很麻烦,现在你可以在你的BaseActivity中写入如下方法:

public final T getView (int id) { try { return (T) findViewById(id); } catch (ClassCastException ex) { Log.e(TAG, “Could not cast View to concrete class.”, ex); throw ex; } }