Title: Method Settag (), Gettag () play a role in view
Why I find such a problem, the main reason is that I encountered when learning Viewholder, then only know how to use. At Google, I found a good explanation on StackOverflow. Hence the translation of one or two.
Source Address: Http://stackoverflow.com/questions/5291726/what-is-the-main-purpose-of-settag-gettag-methods-of-view
Explanation:
For example, you create a lot of similar view, you can add a Onclicklisener attribute to your view, as follows:
Button1.setonclicklistener (new onclicklistener ...); Button2.setonclicklistener (new onclicklistener ...); ...
Then you need to create a unique onclick method for each view, even if their corresponding events are the same. It's like this.
Public void OnClick (View v) { doAction (// 1 for Button1, 2 for Button2, etc.}
This is because have only one onClick
parameter, a View
, and it have to get information other information from instance Varia Bles or final local variables in enclosing scopes. What we really want are to get information from the "views themselves."
Enter Gettag ()/settag ();
Button1.settag (1); Button2.settag (2);
Now we can use the same onclicklistener for each button:
New Onclicklistener () { @Override publicvoid OnClick (View v) { doAction ( V.gettag ());} ;
It's basically a-on-the-a-to-have memories.
This sentence can be carefully tasted.
No actual application has been found, but this article mainly because of Viewholder, en, is viewholder in the application of Settag.
If you want to know more, you can look at the application in Viewholder.
What is the main purpose of Settag () Gettag () Methods of View?