简体   繁体   中英

How to Disable control till Progress Bar is active

I have kept progressbar visibility to invisible from xml. Its respective activity have a Asynch Task when in onPreExecute its visibility is turn out to visible and invisible in onPostExecute . All working fine, however I want my other view control remains disable till progressbar is visible.

Xml

 <ProgressBar
    android:id="@+id/progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    style="?android:attr/progressBarStyleInverse"
    android:visibility="invisible" />

Thanks in Advance

You are having a Asynch Task, it should have the following methods :-

  @Override
    protected void onPostExecute(String result) {

       // Disable the progress bar
      progress.setVisibility(false);

      // Enable all the views that you have disabled earlier in onPreExecute
      view1.setEnable(true);
    }

    @Override
    protected void onPreExecute() {

        // start progress bar here
        progress.setVisibility(true);

       // Disable all your views here

       view1.setEnable(false);
    }

    @Override
    protected void onProgressUpdate(Void... values) {

    }

Here progress is an object of ProgressBar and view1 will be your viewgroup it may be a Imageview, Textview or anything else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM