Scrollview to slide to the bottom and then load data

Source: Internet
Author: User

Train of Thought: Add scrollview to detect events based on sliding

1. First check whether sliding

// Slide to load scrollview. setontouchlistener (New ontouchlistener () {@ overridepublic Boolean ontouch (view V, motionevent event) {// todo auto-generated method stubswitch (event. getaction () {Case motionevent. action_down: break; Case motionevent. action_move: // check the sliding event log. D (TAG, "slide to the bottom"); break; default: Break ;}}});

2. Add detection listening events to the scrollview

However, scrollview cannot add an onscrolllistener listener like listview, so you need to detect it by yourself.

If (view. getmeasuredheight () <= V. getscrolly () + V. getheight () {// log. D (TAG, "slide to bottom") to the bottom ");}

3. Combined Code

// Slide to load scrollview. setontouchlistener (New ontouchlistener () {@ overridepublic Boolean ontouch (view V, motionevent event) {// todo auto-generated method stubswitch (event. getaction () {Case motionevent. action_down: break; Case motionevent. action_move: view = (scrollview) V ). getchildat (0); If (view. getmeasuredheight () <= v. getscrolly () + v. getheight () {// load data code} break; default: Break ;}}});

4. During the test, this will trigger the slide multiple times. The optimization code is as follows:

Private int Index = 0; // slide to load scrollview. setontouchlistener (New ontouchlistener () {@ overridepublic Boolean ontouch (view V, motionevent event) {// todo auto-generated method stubswitch (event. getaction () {Case motionevent. action_down: break; Case motionevent. action_move: Index ++; break; default: break;} If (event. getaction () = motionevent. action_up & index> 0) {Index = 0; view = (scrollview) V ). getchildat (0); If (view. getmeasuredheight () <= v. getscrolly () + v. getheight () {// load data code} return false ;}});

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.