ViewFlipper : Receiver not registered

前端 未结 2 1997
一整个雨季
一整个雨季 2020-12-10 15:08

In my app sometimes I receive this error :

 java.lang.IllegalArgumentException: Receiver not registered: android.widget.ViewFlipper$1@4806a4a8   
at android.         


        
相关标签:
2条回答
  • 2020-12-10 15:51

    Try adding this class to your project:

    public class ContentViewFlipper extends ViewFlipper {
       public ContentViewFlipper( Context context ) {
          super( context );
       }
    
       public ContentViewFlipper( Context context, AttributeSet attrs ) {
          super( context, attrs );
       }
    
       @Override
       protected void onDetachedFromWindow() {
          try {
             super.onDetachedFromWindow();
          }
          catch( Exception e ) {}
       }
    }
    

    And then use it instead of the regular ViewFlipper in your XML:

    <com.yourPackage.ContentViewFlipper
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
    

    Edit

    As this problem seems to be specific to Android 2.1 (API 7), you can make sure you only target this change by copying the layout file(s) with the ViewFlipper to res/layout-v7 and then changing the ViewFlipper to the ContentViewFlipper in those layouts. This way only devices running Android 2.1 will use the fix.

    0 讨论(0)
  • 2020-12-10 16:01

    According to Daniel Lew's solution, create this class:

    import android.content.Context;
    import android.util.AttributeSet;
    import android.widget.ViewFlipper;
    
    public class GabrielleViewFlipper extends ViewFlipper {
        public GabrielleViewFlipper(Context context) {
            super(context);
        }
        public GabrielleViewFlipper(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
        @Override
        protected void onDetachedFromWindow() {
            try {
                super.onDetachedFromWindow();
            }
            catch (IllegalArgumentException e) {
                stopFlipping();
            }
        }
    }
    

    and in your layout don't use the normal ViewFlipper, use GabrielleViewFlipper:

    <your.package.GabrielleViewFlipper
        .
        .
        .
    </your.package.GabrielleViewFlipper>
    
    0 讨论(0)
提交回复
热议问题