Reprinted from: Considerations for using getchildat (INDEX) in listview 1. Principles
In many cases, you do not need to refresh all the data in the listview list. You only need to refresh the data that has changed. In this case, you can use getchildat (INDEX) to obtain the view of a specified position, and refresh the view.
Note: In listview, The getchildat (INDEX) value can only be a subitem of the current visible area (the list can be rolled!
That is, the value range is> = listview. getfirstvisibleposition () & <= listview. getlastvisibleposition ();
1) If you want to obtain the front part, a null pointer is returned;
2) The getchildcount and getcount values will be different (a large number );
3) If getchildat (INDEX). findviewbyid (...) is used to set the value, the scrolling list value will change.
You need to use getfirstvisibleposition () to obtain the first visible position, use the current position-it, and then use getchildat to get the value! That is, getchildat (position-listview. Getfirstvisibleposition (). findviewbyid (...) to set the value
2. If you want to update a row of data, you need to use it with the scrolling status of listview. Generally, the updated data is loaded only when it is not rolled.
// Global variable, used to record the rolling status of scrollview. 1 indicates rolling starts, 2 indicates rolling is in progress, and 0 indicates stopping rolling.
Pseudocode
Listview settings
Public int scrollstates;
Class onscrolllistenerimpl implements onscrolllistener {
@ Override
Public void onscrollstatechanged (abslistview view, int scrollstate ){
Scrollstates = scrollstate;
}
@ Override
Public void onscroll (abslistview view, int firstvisibleitem,
Int visibleitemcount, int totalitemcount ){
Int lastinscreen = firstvisibleitem + visibleitemcount;
}
Listview. setonscrolllistener (New onscrolllistenerimpl ());
Activity
If (scrollstates = onscrolllistener. scroll_state_idle ){
Update View data
}
Getchildat (arg2) exception when listview slides beyond the display area