About the GetView function in Arrayadapter

Source: Internet
Author: User

I wanted to use the GetView in Arrayadapter to get the View object for each item in the ListView. As a result, no matter how I make changes to the View object, it doesn't have an effect. Will not change is taken for granted, because GetView, in fact, is "CreateView". Here is the source code I refer to:

 public view getview (int position, view convertview, viewgroup parent)  {        return createviewfromresource (position,  Convertview, parent, mresource);     }    private view  createviewfromresource (int position, view convertview, viewgroup parent,             int resource)  {         View view;        TextView  text;        if  (convertview == null)  {             view = minflater.inflate (Resource,  parent, false);        } else {             view = convertview;        }         try {             if  (mfieldid == 0)  {                 //  if no custom field is  assigned, assume the whole resource is a TextView                 text =  (TextView)  view;            } else {                 //   otherwise, find the textview field within the layout                 text =  (TextView)  view.findviewbyid (mfieldid);             }        }  catch  (classcastexception e)  {             LOG.E ("Arrayadapter",  "you must supply a resource id for  a textview ");             throw new  illegalstateexception (                      "Arrayadapter requires the resource id to  be a textview ",  e);        }         t item = getitem (position);         if  (item Instanceof charsequence)  {             Text.settext ((charsequence) Item);        } else {             text.settext (Item.toString ());         }        return view;     }


Judging from the code, it must not be what I think. If Convertview equals null, each call to GetView returns a new object. But, why?

My understanding is that adapter, as controller, gets the data down from the model layer and supplies the object up to the view layer. As a giver, you should not be aware of the view layer information. Therefore, it is undesirable to obtain the object of the view layer by adapter.



About the GetView function in Arrayadapter

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.