Home » Android » How to disable all content inside linear layout in android?

How to disable all content inside linear layout in android?

Posted by: admin June 15, 2020 Leave a comment

Questions:

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.

How to&Answers:

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();
   }
});

Answer:

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

myLayout.setEnabled(false); 

Answer:

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