Android ListView的监听事件

Android开发时,最常用的控件之一就是ListView了,而使用ListView的同时,必然需要对它设置监听器,常用的监听器有这么几个
1.OnItemClickListener 
2.OnTouchListener
3.OnScrollListener
1监听器在点击该项目的子项时触发,2监听器在触碰到ListView时触发,3监听器在ListView滚动时触发,
下面几个例子分别表述了具体处理的办法

  

class ItemClickEvent implements OnItemClickListener {  

  

        @Override  

        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,  

                long arg3) {  

            // TODO Auto-generated method stub  

            // arg1.setVisibility(View.GONE);  

  

            // 对子项处理的办法  

  

      

            // BtnCheck(0);  

            System.out.println(arg2);  

        }  

  

    }  

  

  

    class ItemTouchEvent implements OnTouchListener {  

  

        @Override  

        public boolean onTouch(View v, MotionEvent event) {  

            // TODO Auto-generated method stub  

            // System.out.println("触摸..");  

            if (event.getAction() == MotionEvent.ACTION_MOVE) {  

                // System.out.println("MOVE");  //接触到ListView移动时  

                BtnCheck(0);  

            } else if (event.getAction() == MotionEvent.ACTION_UP) {  

                // System.out.println("up");   //离开ListView时  

                BtnCheck(currentPage);  

            } else if (event.getAction() == MotionEvent.ACTION_DOWN) {  

                // System.out.println("down");   //接触到ListView时  

                BtnCheck(0);  

            }  

  

            return false;  

        }  

  

    }  

  

    class LvScrollEvent implements OnScrollListener {  

  

        @Override  

        public void onScroll(AbsListView view, int firstVisibleItem,  

                int visibleItemCount, int totalItemCount) {  

            // TODO Auto-generated method stub  

  

        }  

  

        @Override  

        public void onScrollStateChanged(AbsListView view, int scrollState) {  

            // TODO Auto-generated method stub  

            switch (scrollState) {  

            case OnScrollListener.SCROLL_STATE_IDLE: //  

                BtnCheck(currentPage);  

                // mBusy = false;  

                System.out.println("停止...");  

                break;  

            case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:  

                BtnCheck(0);  

                // mBusy = true;  

                System.out.println("正在滑动...");  

                break;  

            case OnScrollListener.SCROLL_STATE_FLING:  

                BtnCheck(0);  

                // mBusy = true;  

                System.out.println("开始滚动...");  

  

                break;  

            }  

        }  

  

    }  







 







 

 

你可能感兴趣的:(Android ListView的监听事件)