Android ListView Initialization will instantiate how many item

Source: Internet
Author: User

The following is an analysis of the source flow parsing the ListView initialization.

Layoutchildren () is called in Abslistview.onlayout and is implemented by the ListView

@Overrideprotected voidOnLayout (BooleanChangedintLintTintRintb) {Super. OnLayout (Changed, L, T, R, b); Minlayout=true; Final intChildCount =Getchildcount (); if(changed) { for(inti = 0; i < ChildCount; i++) {Getchildat (i). Forcelayout ();        } mrecycler.markchildrendirty (); }            //Subclass ImplementationLayoutchildren (); Minlayout=false; Moverscrollmax= (B-T)/Overscroll_limit_divisor; //Todo:move somewhere sane. This doesn ' t belong in OnLayout ().        if(Mfastscroll! =NULL) {mfastscroll.onitemcountchanged (Getchildcount (), mitemcount); }    }

Listview.layoutchildren:

@Overrideprotected voidLayoutchildren () {Final BooleanBlocklayoutrequests =mblocklayoutrequests; if(blocklayoutrequests) {return; } mblocklayoutrequests=true; Try {            Super. Layoutchildren ();            Invalidate (); if(Madapter = =NULL) {resetlist ();                Invokeonitemscrolllistener (); return; }            Final intChildrentop =Mlistpadding.top; Final intChildrenbottom = Mbottom-mtop-Mlistpadding.bottom; Final intChildCount =Getchildcount (); .. .....default:                if(ChildCount = = 0) {                    if(!Mstackfrombottom) {                        Final intPosition = lookforselectableposition (0,true);                       Setselectedpositionint (position); //initialization will be performed hereSEL =fillfromtop (childrentop); } Else {                        Final intPosition = Lookforselectableposition (mItemCount-1,false);                        Setselectedpositionint (position); Sel= FillUp (mItemCount-1, Childrenbottom); }                } Else {                    if(mselectedposition >= 0 && Mselectedposition <Mitemcount) {sel=fillspecific (mselectedposition, Oldsel==NULL?ChildrenTop:oldSel.getTop ()); } Else if(Mfirstposition <Mitemcount) {sel=fillspecific (mfirstposition, Oldfirst==NULL?ChildrenTop:oldFirst.getTop ()); } Else{sel= fillspecific (0, Childrentop); }                }                 Break; }

Listview.fillfromtop:

Private View fillfromtop (int  nexttop) {        = math.min (mfirstposition, mselectedposition);         = Math.min (mfirstposition, mItemCount-1);         if (Mfirstposition < 0) {            = 0;        }         return FillDown (mfirstposition, nexttop);    }

Listview.filldown:

PrivateView FillDown (intPosintnexttop) {View Selectedview=NULL;
Height of the ListViewintEnd = (Mbottom-mtop); if((Mgroupflags & clip_to_padding_mask) = =clip_to_padding_mask) {End-=Mlistpadding.bottom; } //when initializing pos = 0, if the total item count is less than one screen, execute mitemcount-pos times//If Item is extra a screen, perform end-nexttop times while(Nexttop < end && Pos <Mitemcount) { //Is this the selected item? BooleanSelected = pos = =mselectedposition; View Child= Makeandaddview (pos, Nexttop,true, Mlistpadding.left, selected); Nexttop= Child.getbottom () +Mdividerheight; if(selected) {Selectedview=Child ; } POS++; } setvisiblerangehint (Mfirstposition, Mfirstposition+ Getchildcount ()-1); returnSelectedview; }

Android ListView Initialization will instantiate how many item

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.