Today I encountered a very strange problem, I set a ListView has 10 item, when the number of my list.getcount for the For Loop, when the 6th item, the resulting view object is null, which makes me very puzzled, After a query, understand the problem is how to share with you:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/3A/74/wKioL1O7t5iTMp4kAAC_DbxzQ8E536.jpg "title=" Indicator briefs. png "alt=" wkiol1o7t5itmp4kaac_dbxzq8e536.jpg "/>
The listview portion of the Red box section of the slice. This actually involves the memory processing problem of the Android ListView control: When we load the ListView, if the ListView has more data, it is not fully displayed, but is all the data loaded? The answer is no, the number of ListView loading is the current screen display of more than four, respectively, the top and bottom of each buffer two, this is the problem. When I have a ListView with 10 item, but my current layout shows up to 4, so when I get to the seventh one, I get an empty item. The solution is as follows:
public class Measureitemlistener implements onitemclicklistener{
@Override
public void Onitemclick (adapterview<?> arg0, View arg1, int arg2,
Long Arg3) {
FIRSTLOCATION=ARG2;
dataldialog= New Loaddialogdao (Getactivity (), "Data Loading ...");
Dataldialog.show ();
for (int i=0;i<measure_type_list.getcount (); i++) {
int firvisible=measure_type_list.getfirstvisibleposition (); \ \ Gets the index of the first visible item
View V=measure_type_list.getchildat (i-firvisible);
if (v!=null) {
if (arg2 = = i) {
V.setbackgroundcolor (R.color.lightblue);
} else {
V.setbackgroundresource (r.drawable.list_item_selector);
}
}
}
}
};
The solution is to add the red character part, get the index of the first visible item on the screen, and subtract this value from the current child's index to get the current object.
This article from "Mo Panic, raise straight forward" blog, please be sure to keep this source http://kunyali.blog.51cto.com/4890065/1435989