Android-Little questions about the ListView after setting the Onscrolllistener onscrollstatechanged () and the Onscroll method does not listen to the problem

Source: Internet
Author: User

About the ListView after setting the onscrolllistener onscrollstatechanged() and onscroll method does not listen to the problem:

Reason:

The first Onscrolllistener is the focus scrolling listener event, which needs to have focus in order to respond. If the listview is embedded in the ScrollView , the height of the ListView is calculated dynamically and the height is set. Then the user drag the interface, causing the scroll is ScrollView scrolling, rather than the scroll of the ListView , when the focus is ScrollView taken away,thelistview Naturally does not respond to the Onscrolllistener monitoring, the same on the simulator using the mouse wheel slide the ListView The resulting non-responsive Onscrolllistener is also true.

Assumptions and Workarounds:




If the ListView is at the bottom of the ScrollView at this point, and there are some data controls above the ListView that need to be displayed, What if the ListView needs to dynamically set the height and need to complete the paging load function?

Don't be nervous, there are ways to do it, then look down:

1. I started with listening scrollview swipe to the bottom to load more ways, But this leads to a problem when scrollview inline Span style= "Font-family:consolas" >listview time, listview notifydatasetchanged () method because of the need to get interface resources, Scrollview notifydatasetchanged () method, the focus of the capture led to the main line incurring, then this situation is not.

2. Then I want to try to customize scrollview embed Span style= "Font-family:consolas" >listview when automatically focus on listview But this is another problem, scrollview so pass!

Finally I use the killer, listview + headview + footerview Span style= "font-family: Arial", that is, divided into three pieces, custom headview content, custom footerview The display content, is simple and general, fully meet my needs, but there is a need to note that this turntable ( listview there are headview lsitview set Onitemclicklistener, then one method of Onitemclicklistener:

Public void Onitemclick (adapterview<?> arg0, View arg1, int arg2,long arg3) {

}

At this point the click Position should be arg3, not arg2, because the ListView Headview will occupy an item.


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.