Method One:
The Setonscrolllistener (New Abslistview.onscrolllistener ()) is used to determine the first entry shown after sliding, and the size of the first entry before sliding,
This method is logically simple, but it must be slid to the current first entry hidden before it can work, and when the height of a single item in the ListView is very large, this method is not good. The code is as follows:
Lv_shiti_content.setonscrolllistener (NewAbslistview.onscrolllistener () {Booleanscrollflag=false;//Mark whether to slide Booleanisfirst=true;//mark the first entry, because the first time you come in lastvisibleitemposition defaults to 0,//if the first displayed entry for the ListView is not the first (the table below is 0), then the firstvisibleitem>lastvisibleitemposition will also appear.//so the first time to enter the operation, the second came in has been assigned to the lastvisibleitemposition, you can judge intLastvisibleitemposition;//mark the last display location@Override Public voidOnscrollstatechanged (Abslistview view,intscrollstate) { if(scrollstate==1| | scrollstate==2){ //where 1 means sliding, equivalent to AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL//2 means inertial sliding is equivalent to AbsListView.OnScrollListener.SCROLL_STATE_FLINGscrollflag=true; }Else{Scrollflag=false; }} @Override Public voidOnscroll (Abslistview view,intFirstvisibleitem,intVisibleItemCount,intTotalitemcount) { if(!IsFirst) { if(firstvisibleitem>lastvisibleitemposition) { //logic to do when performing an upward swipe} lastvisibleitemposition=firstvisibleitem;//Record Current Entryisfirst=false; } } });
Method Two:
Using the Setontouchlistener (new View.ontouchlistener () method, this method can be judged as long as there is a little moving distance.
Special Note: The Android control's event pass is passed directly to the innermost layer by default, and the event is interrupted only when it is slid up and down, so the first event we get is the move event.
Our logic is also done in the move event, which results in the same values obtained for the lasty and Movey (see code below)
So we have to judge that only the first time you come in, get lasty. After all, lasty directly records the current Movey. Otherwise the lasty and Movey will always be the same value each time.
Lv_shiti_content.setontouchlistener (NewView.ontouchlistener () {@Override Public BooleanOnTouch (View V, motionevent event) {if(Isfirstclick) {//only the first time you come in. Assigns a value to the lasty using the method that gets the position, and the subsequent value is the last move coordinate//If you do not make this decision, the Lasty and Movey are the same value each time, because the Y value obtained here is actually the value of the move,//because in the ListView, the down event is passed by default to the destination, where the down event cannot be responded to. lasty=event.gety (); Isfirstclick=false; } Switch(Event.getaction ()) { CaseMotionevent.action_move:floatMovey =event.gety (); LOG.E ("Movey_start", movey+ ""); if(movey<lasty) { if(!Newpageisopen) {Intent Intent=NewIntent (Getactivity (), shitidiantestactivity.class); StartActivity (Intent); Newpageisopen=true; }} lasty=Movey; Break; } return false; } });
Determine if the ListView is a slide or slide