Android Development, one of the most common controls is the ListView, while using the ListView, it is necessary to set the listener, the common listener has so few
1.OnItemClickListener
2.OnTouchListener
3.OnScrollListener
1 The listener is triggered when the child of the item is clicked, the 2 listener is triggered when it touches the ListView, and the 3 listener is triggered when the ListView scrolls.
The following examples describe the specific approach
classItemclickeventImplementsOnitemclicklistener {@Override Public voidOnitemclick (adapterview<?> arg0, View arg1,intArg2,LongArg3) { //TODO auto-generated Method Stub//arg1.setvisibility (View.gone); //ways to handle child items//btncheck (0); System.out.println (ARG2); } } classItemtoucheventImplementsOntouchlistener {@Override Public BooleanOnTouch (View V, motionevent event) {//TODO auto-generated Method Stub//System.out.println ("touch.."); if(event.getaction () = =motionevent.action_move) { //System.out.println ("MOVE"); //when touching the listview moveBtncheck (0); } Else if(event.getaction () = =motionevent.action_up) { //System.out.println ("Up"); //when you leave the ListViewbtncheck (currentpage); } Else if(event.getaction () = =Motionevent.action_down) { //System.out.println ("Down"); //when exposed to a ListViewBtncheck (0); } return false; } } classLvscrolleventImplementsOnscrolllistener {@Override Public voidOnscroll (Abslistview view,intFirstvisibleitem,intVisibleItemCount,intTotalitemcount) { //TODO auto-generated Method Stub} @Override Public voidOnscrollstatechanged (Abslistview view,intscrollstate) { //TODO auto-generated Method Stub Switch(scrollstate) { CaseOnscrolllistener.scroll_state_idle:// btncheck (currentpage); //mbusy = false; System.out.println ("Stop ..."); Break; CaseOnScrollListener.SCROLL_STATE_TOUCH_SCROLL:BtnCheck (0); //mbusy = true; System.out.println ("Sliding ..."); Break; CaseOnScrollListener.SCROLL_STATE_FLING:BtnCheck (0); //mbusy = true; System.out.println ("Start scrolling ..."); Break; } } }
Listening Events for Android listview