What is the main purpose of Settag () Gettag () Methods of View?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.