How to prevent ViewFlipper from looping

前端 未结 3 1067
梦毁少年i
梦毁少年i 2021-01-22 16:43

I am developing an application in which I am using a ViewFlipper with a custom OnTouch implementation. In the ViewFlipper, I have about 2

3条回答
  •  春和景丽
    2021-01-22 17:40

    I detect end of children by custom ViewFlipper

    public class ExViewFlipper extends ViewFlipper {
    
      private OnChangeViewListener mOnChangeViewListener;
    
      public ExViewFlipper(Context context) {
        super(context);
      }
    
      public ExViewFlipper(Context context, AttributeSet attrs) {
        super(context, attrs);
      }
    
      public interface OnChangeViewListener {
    
        /**
         * call on Change view
         * 
         * @param index next index
         * @param hasNext true if next view is exist
         */
        void onChange(int index, boolean hasNext);
      }
    
      public void setOnChangeViewListener(OnChangeViewListener listener) {
        mOnChangeViewListener = listener;
      }
    
      @Override
      public void showNext() {
    
        super.showNext();
    
        if (mOnChangeViewListener != null) {
          mOnChangeViewListener.onChange(getDisplayedChild(), true);
        }
      }
    
      @Override
      public void showPrevious() {
    
        super.showPrevious();
    
        if (mOnChangeViewListener != null) {
          mOnChangeViewListener.onChange(getDisplayedChild(), false);
        }
      }
    
      public boolean isFirstItem() {
    
        return getDisplayedChild() == 0;
      }
    
      public boolean isLastItem() {
    
        return getDisplayedChild() == getChildCount() - 1;
      }
    }
    

提交回复
热议问题