. Net programmers play Android development-ListView rolling event

Source: Internet
Author: User

. Net programmers play Android development-ListView rolling event

The ListView in Android can slide up and down, and the up and down activities can load data by page. In this section, we will see the scrolling event of ListView.

The rolling event of ListView is mainly implemented through the setOnScrollListener listener. It mainly includes two methods: onScroll and onScrollStateChanged. onScrollStateChanged is mainly used to monitor the rolling status.

Add data to the ListView during the sliding process. The ListView mainly has three states: SCROLL_STATE_TOUCH_SCROLL, SCROLL_STATE_FLING, and SCROLL_STATE_IDLE.

 

Lv. setOnItemClickListener (new OnItemClickListener () {@ Override public void onItemClick (AdapterView
 Arg0, View arg1, int arg2, long arg3) {TextView tname = (TextView) arg1.findViewById (R. id. tvname); // name TextView tmodel = (TextView) arg1.findViewById (R. id. tvmodel); // type TextView tprice = (TextView) arg1.findViewById (R. id. tvprice); // unit price TextView tcode = (TextView) arg1.findViewById (R. id. tvcode); // code Toast. makeText (getApplicationContext (), "current product name:" + tname. getText () + ", encoding:" + tcode. getText (), 30 ). show () ;}}); lv. setOnScrollListener (new OnScrollListener () {@ Overridepublic void onScroll (AbsListView arg0, int arg1, int arg2, int arg3) {// TODO Auto-generated method stub} @ Overridepublic void onScrollStateChanged (AbsListView arg0, int arg1) {// TODO Auto-generated method stub rolling status listener if (arg1 = AbsListView. onScrollListener. SCROLL_STATE_TOUCH_SCROLL) {// The finger does not exit the screen and is sliding Toast. makeText (getApplicationContext (), "the finger did not exit the screen, sliding", 30 ). show (); Map
 
  
Map = new HashMap
  
   
(); Map. put ("code", "encoding: 10"); map. put ("name", "name: Ipad"); map. put ("price", "price: 22"); map. put ("model", "unit: 22"); mapList. add (map); // adp. notifyDataSetChanged (); SimpleAdapter sAdapter = (SimpleAdapter) lv. getAdapter (); sAdapter. notifyDataSetChanged ();} else if (arg1 = AbsListView. onScrollListener. SCROLL_STATE_FLING) {// slide Toast before leaving the screen. makeText (getApplicationContext (), "slide hard before leaving the screen", 30 ). show ();} else if (arg1 = AbsListView. onScrollListener. SCROLL_STATE_IDLE) {// stop sliding Toast. makeText (getApplicationContext (), "stop sliding", 30 ). show ();}}});
  
 

 

 

 



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.