How to disable all content inside linear layout in android?

24,349

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();
   }
});
Share:
24,349
Sushant Bhatnagar
Author by

Sushant Bhatnagar

I have the analytical mind necessary to write code and the big-picture mentality to make it innovative and unique. I also enjoy overseeing projects, organising people and channelling them into areas where they can make the best use of their talents. I began my IT career as a front-end developer. My job entailed working with teams of developers to write apps with varying functionalities from mobile to web application. I had experimented with different technologies C#, ASP.NET MVC , Native - Android , Xamarin.Android , Xamarin.iOS , Git , Gitlub, Node.js during this journey. Collaborating with other developers not only honed my coding skills but also taught me the value of how to effectively work with others and subdivide tasks to improve efficiency and ensure smooth teamwork. I later decided to combine my skills towards becoming a DevOps Engineer at Gaussian Networks by adopting cloud - AWS. With me at the helm coordinating the development and IT Operations team, I was able to design CI/CD pipelines that improved the company's ability to design, debug and release software by 20%. Some of the key requirement that I have extensive experience with include: Experience with mobile ui/ux design for multiple devices. In depth knowledge of Google Play/ App Store publishing policies. Good understanding of mobile platform challenges and limitations. Good analytical , logic &amp; critical cases thinking skill Experience with micro service environment setup on Cloud - Containerisation Experience with CI/CD pipelines setup. Lead the project from scratch to production go live. End to end ownership of project delivery.

Updated on July 09, 2022

Comments

  • Sushant Bhatnagar
    Sushant Bhatnagar almost 2 years

    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.

  • Andrew Arace
    Andrew Arace over 10 years
    The question was to disable the view, not to hide it.