(Android) How to disable all buttons / CheckBoxes / Other Widgets in a ScrollView but not disable scrolling

advertisements

I have an Activity that contains a ScrollView. This ScrollView contains a TableLayout many Widgets inside of it. When the user clicks a Button, I would like to disable all of the Widgets inside the TableLayout, but not disable the scrolling. The user needs to be able to look at what is inside of the ScrollView but simply not interact with it. I have searched around the internet and haven't been able to find an answer that works for me. If you have any solutions, please post them here. Any help is appreciated greatly.


A ScrollView extends ViewGroup, so you can use the getChildCount() and getChildAt(index) methods to iterate through your children. So, it would look something like this:

ScrollView scroll = (ScrollView) findViewById(R.id.yourscrollid);
for ( int i = 0; i < scroll.getChildCount();  i++ ){
    View view = scroll.getChildAt(i);
    view.setEnabled(false); // Or whatever you want to do with the view.
}