Listening Events for Android listview

Source: Internet
Author: User

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

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.