Sushant Bhatnagar
Sushant Bhatnagar

Reputation: 3774

How to disable all content inside linear layout in android?

Hi I want to disable all content of linear layout by when activity is loaded , when user click on that are , it display alert msg .

After click on activate button , linear layout should be enabled. Whether it is possible or not?

I am able to disable all content inside linear layout using following code:

LinearLayout myLayout = (LinearLayout) findViewById(R.id.linearLayout1);
for ( int i = 0; i < myLayout.getCount();  i++ ){
    View view = myLayout.getChildAt(i);
    view.setVisibility(View.GONE); // Or whatever you want to do with the view.
 }

I want to display alert dialog when user click on disabled area.

please suggest me usable link or sample code.

Upvotes: 10

Views: 26997

Answers (3)

Issac Balaji
Issac Balaji

Reputation: 1441

Just do it, will work instead of getting all view and making disable them

myLayout.setEnabled(false); 

Upvotes: 0

Anand Tiwari
Anand Tiwari

Reputation: 1598

You need to do as follows:

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

Then create an alert Dialog and then

myLayout.setOnclickListener(new OnClickListener(){

   onClick(){
     dialog.show();
   }
});

Upvotes: 17

Yugandhar Babu
Yugandhar Babu

Reputation: 10349

You can call directly as below, no need to set for each view inside it.

myLayout.setVisibility(View.INVISIBLE); // or View.GONE as you needed

Upvotes: -12

Related Questions