Android Question about add disable/enable event to TabStrip

Discussion in 'Android Questions' started by laomms, Aug 12, 2018.

  1. laomms

    laomms Member Licensed User

    I use ResizeAndCrop sample(https://www.b4x.com/android/forum/threads/resize-and-crop.19550/#content) in TabStripViewPager(https://www.b4x.com/android/forum/threads/tabstripviewpager-better-viewpager.63975/#post-404659)

    IMG_20180812_073357.jpg

    but when i DrawRect the image, the TabStrip will follow moveing, is it possible when "picture" tab is enabled, the slide control will disabled untill I click the finish button.
    I see the source to add setDisabled event to tabstrips in github:
    Code:
    public class CustomTabStrip extends PagerSlidingTabStrip {
        
    private boolean disabled;

        
    public CustomTabStrip(Context context) {
            super(context);
        
    }

        public CustomTabStrip(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        public CustomTabStrip(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }

        public void setDisabled(boolean disabled) {
            this.disabled = disabled;
        }

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            return disabled || super.onInterceptTouchEvent(ev);
        }
    }
    If can add above to the lib source ? or this:
    Code:
    public class ScrollableViewPager extends PagerSlidingTabStrip {
        
    private boolean canScroll = true;
        
    public ScrollableViewPager(Context context) {
            super(context);
        
    }
        public ScrollableViewPager(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
        public void setCanScroll(boolean canScroll) {
            this.canScroll = canScroll;
        }
        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            return canScroll && super.onTouchEvent(ev);
        }
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            return canScroll && super.onInterceptTouchEvent(ev);
        }
    }

    Code:
    Sub TabStrip1_PageSelected (Position As Int)
        
    Log($"Current page: ${Position}"$)
        
    If Position=2 Then
            
    Dim jo As JavaObject = TabStrip1
            jo = jo.GetField(
    "tabStrip")
            jo.RunMethod(
    "setDisable"Array(disabled))
        
    End If
     
    End Sub
     
    Last edited: Aug 12, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

    Currently you cannot disable the swiping gesture. You can however show the custom view above the TabStrip instead of putting it inside. You can later put it back inside.
     
  3. alwaysbusy

    alwaysbusy Expert Licensed User

    I'm having the same issue. Having the disabled would be fantastic, but I understand. I see in the designer the tabstrip has an enabled checkbox. We cannot access this property from code?

    Can you elaberate a bit on the above statement (I'm a bit out of shape on B4A :()?

    I currently have a scrolling canvas in a tabstrip and at a certain point on dragging on the canvas, the tabstrip starts changing panels. So when the dragging on the canvas starts, I somehow remove the panel holding the canvas from the tabstrip (?) and put in directly on the activities layout until I stop dragging. Then I put it back in the tabstrip, correct?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    This will not help. It is part of the template of custom views.

    Handle the PageSelected event. When the relevant page is selected remove the ScrollView(?) from its parent (tip: use B4XView and you will not need to remember the differences between the platforms). Now add it to an elevated panel that was previously invisible and is not a child of TabStrip. Add a "close" button to return the canvas back to the TabStrip.
     
    alwaysbusy likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice