Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable the segmented control #7

Closed
amrboxit4me opened this issue Sep 5, 2018 · 6 comments
Closed

Disable the segmented control #7

amrboxit4me opened this issue Sep 5, 2018 · 6 comments

Comments

@amrboxit4me
Copy link

I disabled the segment by setEnable(false) but it doesn't work
So I used the following code but it is better to make disable feature

    private void disableEnableControls(boolean enable, ViewGroup vg) {
        for (int i = 0; i < vg.getChildCount(); i++) {
            View child = vg.getChildAt(i);
            child.setEnabled(enable);
            if (child instanceof ViewGroup) {
                disableEnableControls(enable, (ViewGroup) child);
            }
        }
    }
@RobertApikyan
Copy link
Owner

You want to disable segment selection, right ?

@RobertApikyan
Copy link
Owner

If it's true, than here is the example how to disable segment...
Disable selection for segment with position 3.
Add OnSegmentSelectListener and control the segment selection.

segmentedControl.addOnSegmentSelectListener(new OnSegmentSelectedListener<String>() {
            @Override
            public void onSegmentSelected(SegmentViewHolder<String> segmentViewHolder, boolean isSelected, boolean isReselected) {
                if (segmentViewHolder.getAbsolutePosition() == 3){  // disable segment 3 
                    segmentViewHolder.onSegmentSelected(false,false);
                }
            }
        });

@RobertApikyan
Copy link
Owner

Disable all segments

    segmentedControl.addOnSegmentSelectListener(new OnSegmentSelectedListener<String>() {
            @Override
            public void onSegmentSelected(SegmentViewHolder<String> segmentViewHolder, boolean isSelected, boolean isReselected) {
                segmentViewHolder.onSegmentSelected(false,false);
            }
        });

@RobertApikyan
Copy link
Owner

Let me close the issue, but fill free to reopen it, if you have any questions

@lavatechdev
Copy link

That doesn't solve the problem as view is still clickable. What if you would like to disable possibility of clicking any segment and keep selection as it was before disabling segmentedControl?

@fefereliezer
Copy link

fefereliezer commented Jun 15, 2021

Call this function to disable

public static void disableSegmentedControl(View view) {
       if ((view != null)) {
           view.setClickable(false);
           view.setLongClickable(false);
       }
       if (view instanceof ViewGroup) {
           for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
               View innerView = ((ViewGroup) view).getChildAt(i);
               disableSegmentedControl(innerView);
           }
       }
   }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants