Code example for Gallery

Methods: getCount, getSelectedItemPosition, setSelection

0
                    upX=(int) event.getX();//È¡µÃËÉ¿ªÊ±µÄ×ø±ê   
                    int index=0;   
                    if(upX-downX>100)//´Ó×óÍϵ½ÓÒ£¬¼´¿´Ç°Ò»ÕÅ   
                    {    
                        //Èç¹ûÊǵÚÒ»£¬ÔòÈ¥µ½Î²²¿    
                        if(gallery.getSelectedItemPosition()==0)   
                           index=gallery.getCount()-1;   
                        else   
                            index=gallery.getSelectedItemPosition()-1;   
                    }    
                    else if(downX-upX>100)//´ÓÓÒÍϵ½×󣬼´¿´ºóÒ»ÕÅ   
                    {    
                        //Èç¹ûÊÇ×îºó£¬ÔòÈ¥µ½µÚÒ»    
                        if(gallery.getSelectedItemPosition()==(gallery.getCount()-1))   
                            index=0;   
                        else   
                            index=gallery.getSelectedItemPosition()+1;   
                    }    
                    //¸Ä±ägalleryͼƬËùÑ¡£¬×Ô¶¯´¥·¢ImageSwitcherµÄsetOnItemSelectedListener    
                    gallery.setSelection(index, true);   
                    return true;    
                }    
                return false;    
            }