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