关于ViewFlipper在Android2.1及以上版本中的bug
频繁使用ViewFlipper这个控件,可以实现比较实用的页面切换,加上比Gallery方便扩展,所以会常常用到,但是在Android2.1及以上版本中出现系统bug,在进行横竖屏切换时会有如下系统报错:java.lang.IllegalArgumentException: Receiver not registered: android.widget.ViewFlipper$1@43dee3c0在网上查到的原因是由于 onDetachedFromWindow() 莫名其妙地在 onAttachedToWindow() 之前被调用了。解决方法是重写ViewFlipper的相关函数,try-catch一下完事,如下:
import android.content.Context;import android.util.AttributeSet;import android.widget.ViewFlipper;
public class MyViewFlipper extends ViewFlipper {
public MyViewFlipper(Context context) {super(context);// TODO Auto-generated constructor stub}public MyViewFlipper(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stub}
@Overrideprotected void onDetachedFromWindow () {?try {?super.onDetachedFromWindow();?} catch (IllegalArgumentException?e) {?stopFlipping();?}?}}