When the first position of the gridview is loaded repeatedly, the first position is overwritten by the last position information.

Source: Internet
Author: User

When using the gridview, the printed results may sometimes cause repeated data loading. layout problems may cause this problem. To solve this problem, you only need to fix the layout parameters, for example, it is a specific value of 100dip, or set it to fill_parent. Another type of data duplication problem is that only the first position data is loaded. (the first position is displayed before and after the printed result, that is, position = 0). How can this problem be solved? The Code is as follows:

If (position = 0 & modelcontent. hasfirstloaded)
{
Return convertview;
}

If (position = 0)
{
Modelcontent. hasfirstloaded = true;
}

}

When a flag is given to determine and filter, the problem is solved, and the first position may be overwritten by the last position information. What should I do? See the following code:

Private view firstview = NULL;

Public View getview (INT position, view convertview, viewgroup parent)
{
Int id = position;
Productviewcache = NULL;
Productvo = NULL;
Productvo = (productvo) datalist. Get (ID); // instantiate an object of the Product Information Class
If (convertview = NULL)
{
Convertview = minflater. Inflate (R. layout. suggest_gridview_adapter, null );
Productviewcache = new productviewcache (convertview, itemh );
Convertview. settag (productviewcache );
}
Else
{
Productviewcache = (productviewcache) convertview. gettag ();
}

// Fix repeated loading at the first position
If (position = 0 & modelcontent. hasfirstloaded)
{
Return firstview;
}

If (position = 0)
{
Modelcontent. hasfirstloaded = true;
}

......

......

......

// Solve the problem that the first position is overwritten by the last position information

If (position = 0 ){
Firstview = convertview;
}

Return convertview;

}

Cause Analysis: After filtering the first position, when converview saves the last position data information, it runs the first position again (the first position is repeated ),

If (position = 0 & modelcontent. hasfirstloaded)
{
Return firstview;
}

The judgment statement directly returns convertview, that is, the last position information. Therefore, the last position data information is displayed at the first position, and the first position information is saved!

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.