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!