How to disable all content inside a linear layout in android?

Hi, I want to disable all the contents of the linear layout, when the activity loads, when the user clicks on it, a message is displayed with a message.

After clicking the "Activate" button, you must enable the linear layout. Is this possible or not?

I can turn off all content inside the linear layout using the 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 a warning dialog when a user clicks on a disabled area.

offer me a useful link or sample code.

+4
source share
3 answers

You need to do the following:

 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 a warning dialog and then

 myLayout.setOnclickListener(new OnClickListener(){ onClick(){ dialog.show(); } }); 
+8
source

Just do it, work, not get the whole idea and turn them off.

 myLayout.setEnabled(false); 
+2
source

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

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

Source: https://habr.com/ru/post/1393995/


All Articles