Getchildat (arg2) exception when listview slides beyond the display area

Source: Internet
Author: User
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

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.