2

I have 4 LinearLayouts in a RelativeLayout and I am also using an ImageView. When the ImageView is displayed I want to disable the 4 LinearLayouts and their contents. Each LinearLayout contains 4 buttons. Shown below is my function to disable and enable these layouts. Can someone help me understand why this isn't working?

private void disablelayout(final LinearLayout l1,final LinearLayout l2,final LinearLayout l3,final LinearLayout l4)
    {
        l1.setEnabled(false);
        l2.setEnabled(false);
        l3.setEnabled(false);
        l4.setEnabled(false);

    }
    private void enablelayout(final LinearLayout l1,final LinearLayout l2,final LinearLayout l3,final LinearLayout l4)
    {
        l1.postDelayed(new Runnable(){             
             @Override             
             public void run() {                 
                 l1.setEnabled(true); 
                 l2.setEnabled(true); 
                 l3.setEnabled(true); 
                 l4.setEnabled(true); 
             }         
             }, 3000);
    }
Whitewall
  • 597
  • 1
  • 7
  • 18
star angel
  • 520
  • 2
  • 7
  • 14
  • i dont want to make it invisible.layouts should be visible.but user should not be able to click on buttons in th layouts – star angel Jun 10 '11 at 13:41

5 Answers5

3
private void enableDisableView(View view, boolean enabled) {
    view.setEnabled(enabled);

    if ( view instanceof ViewGroup ) {
        ViewGroup group = (ViewGroup)view;

        for ( int idx = 0 ; idx < group.getChildCount() ; idx++ ) {
            enableDisableView(group.getChildAt(idx), enabled);
        }
    }
}
Sagar Waghmare
  • 4,702
  • 1
  • 19
  • 20
0
Use can use this for hide the whole layout

l1.setVisibility(View.GONE);
l2.setVisibility(View.GONE);
l3.setVisibility(View.GONE);
l4.setVisibility(View.GONE);

whenever you want to display particular layout then you can 

l1.setVisibility(View.VISIBLE);
Vishesh Chandra
  • 6,951
  • 6
  • 35
  • 38
0

Use setVisibility() to either INVISIBLE or GONE.

vipw
  • 7,593
  • 4
  • 25
  • 48
  • if i set this the linearlayouts will be invisible.rt?but i dnt want to make it invisible – star angel Jun 10 '11 at 13:35
  • 1
    I thought by disabled you meant not able to be seen. Perhaps you're looking for something like this: http://stackoverflow.com/questions/3205384/android-mass-enable-disable-buttons – vipw Jun 11 '11 at 15:44
0

Use like this:

l1.setVisibility(View.GONE);
l2.setVisibility(View.GONE);
l3.setVisibility(View.GONE);
l4.setVisibility(View.GONE);
Balaji Khadake
  • 3,449
  • 4
  • 24
  • 38
0

Set "Clickable" property for all items to false. The method is setClickable(boolean).
After that no one could click it. Also you could look into this question: How to disable an Android button

Community
  • 1
  • 1
woodshy
  • 4,085
  • 3
  • 22
  • 21
  • i tried this...but still i can click on buttons...i had set this property for layouts..that s y i asked u...is it necessary to set dis to all the cntrls in d layouts..it s really difficult.. – star angel Jun 10 '11 at 13:53
  • Each View has "Duplicate parent state" property (in visual editor too). Set it to true for all buttons and other Vies you want. After thet use setEnabled(false); to layout. It should work. – woodshy Jun 10 '11 at 14:00
  • i had set the Duplicate parent state property for all buttons.but still same problem... – star angel Jun 10 '11 at 14:08