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 ;}});