Used to Findviewbyid, each use also have to add cast to see a video today (according to the IDE used in the video inference, it should be a few years ago video), using a method, you can not use Findviewbyid each time to add cast.
I refine it according to the wording in the video, specifically:
Create a baseactivity and let it inherit activity, adding the following method to it:
because it is findview, the generic type should inherit viewprotected <t extends view> T genericfindviewbyid (int id) {//return return to View, Plus generic Treturn (T) Findviewbyid (ID);}After that, the activity will be used to inherit baseactivity, and then use the Genericfindviewbyid directly instead of the Findviewbyid.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android simplifies Findviewbyid type conversions with generics