5

I have a simple layout, a listview, and two icons for filtering and sorting options. When I click on the either of the two options I have a layout that is placed above the listview and covers only 60% of the screen thereby making the listview below it partially visible. What I want to achieve is to disable the scrolling for that listview also, none of the listview item should be clickable as long as the overlay is visible.

I tried using

setEnabled(false)
setClickable(false)

on the listview but it doesn't make any difference. What are other ways to achieve this.

3 Answers 3

1

I suggest that the overlay will be on the whole screen. Then, you can wrap the overlay with (vertical) linear layout with weights (to achieve 60%/40% ratio). In the linear layout, place your current overlay as the first child and as a second child put a transparent view that will block touch events. This way you won't need to do any modifications to the list view.

Sign up to request clarification or add additional context in comments.

2 Comments

Why not make the filter option container a child of the overlay (you will need to make the overlay relative/frame layout). Have you tried what I suggested?
I took your suggestion, but instead of using transparent second child to block touch events, my semi transparent overlay mask does that work for me.
0

You can use this for disabling the parent scrollview

parentview.requestDisallowInterceptTouchEvent(true);

if the overlay is visible .

1 Comment

that would make it perfect. Thanks
0

To disable the scrolling you can use the OnTouchListener()

listView.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_MOVE) {
            return true; // Indicates that this has been handled by you and will not be forwarded further.
        }
        return false;
    }
});

OR

listView.setScrollContainer(false);

For disabling the click, In your custom ArrayAdapter override isEnabled method as following

@Override
public boolean isEnabled(int position) {
    return false;
}

3 Comments

what if I want to enable clickability again?
"return true;" in isEnabled. You may use a boolean and return that based on your need.
if I am not wrong isEnabled would work when I am creating list initially, that is when I first load the list, I understand that in such a case isEnabled would work based on any condition I apply and set the view's clickability, but would it even work after the listview is already created and then after that on some user click action I wish to decide clickability? I am a bit confused on this front.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.