Android Question about add disable/enable event to TabStrip

laomms

Member
Licensed User
Longtime 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:
B4X:
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:
B4X:
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);
    }
}


B4X:
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:

alwaysbusy

Expert
Licensed User
Longtime User
You can however show the custom view above the TabStrip instead of putting it inside. You can later put it back inside.
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?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I see in the designer the tabstrip has an enabled checkbox
This will not help. It is part of the template of custom views.

Can you elaberate a bit on the above statement (I'm a bit out of shape on B4A :()?
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.
 
Upvote 0
Top