You do not need ViewInject to simplify your findViewById and viewinject.
This blog will be very short. You may be bored with writing code.findViewById, Me too. At this time, you may choose to write with annotations.ViewInjectTo simplify this operation,... I really don't like itViewInject.
Now, I want to simplify it myself.findViewById, How to use it after it is simplified? See the following code,
TextView textView = V.f(this, R.id.textView);ImageView imageView = V.f(convertView, R.id.image);
This solution solves two problems,
1. simplified the 'findviewbyid' method. 2. If no code is available, the code length type conversion will be increased.
Then how should we implement these twoV.fHow? It is actually very simple.
/** * view utils * @author loader * */public class V { /** * activity.findViewById() * @param context * @param id * @return */ public static <T extends View> T f(Activity context, int id) { return (T) context.findViewById(id); } /** * rootView.findViewById() * @param rootView * @param id * @return */ public static <T extends View> T f(View rootView, int id) { return (T) rootView.findViewById(id); }}
This is done with just one line of code. Here we use the type derivation feature of the java generic method.
OK. This blog is so simple. Everyone can copy the code.
Copyright Disclaimer: This article is from the Loader's Blog and cannot be reproduced without the permission of the blogger.