Question Of Using Contentloadingprogressbar

Posted on

android.support.v4.widget.ContentLoadingProgressBar is subclass of ProgressBar. That waits a minimum fourth dimension to last dismissed earlier showing. Once visible, the progress bar volition last visible for a minimum amount of fourth dimension to avoid “flashes” inward the UI when an upshot could accept a largely variable fourth dimension to consummate (from none, to a user perceivable amount).

 I TRY to purpose it inward this exercise. To display too enshroud it past times calling its show() and hide() methods. By calling show(), show the progress thought afterward waiting for a minimum delay. If during that time, hide() is called, the thought is never made visible.

When long progress run afterward show(), the ContentLoadingProgressBar shown afterward a brusk time.
When brusk progress run afterward show(), the ContentLoadingProgressBar volition non shown.

But the work is: once ContentLoadingProgressBar no shown once, it volition non last shown again! I don’t is it normal behavior, or anything wrong.


Here is my exercise:

MainActivity.java

package com.blogspot.android_er.androidcontentloadingprogressbar;  import android.os.AsyncTask; import android.os.Bundle; import android.os.SystemClock; import android.support.v4.widget.ContentLoadingProgressBar; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.ProgressBar;  populace cast MainActivity extends AppCompatActivity {      Button btnStartShortProgress, btnStartLongProgress;     ProgressBar progressBar;     ContentLoadingProgressBar contentLoadingProgressBar;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         btnStartShortProgress = (Button)findViewById(R.id.startshortprogress);         btnStartLongProgress = (Button)findViewById(R.id.startlongprogress);         progressBar = (ProgressBar)findViewById(R.id.ProgressBar);         contentLoadingProgressBar =                 (ContentLoadingProgressBar)findViewById(R.id.ContentLoadingProgressBar);          btnStartShortProgress.setOnClickListener(new View.OnClickListener() {             @Override             populace void onClick(View view) {                 btnStartShortProgress.setEnabled(false);                 btnStartLongProgress.setEnabled(false);                 MyAsyncTask myAsyncTask = novel MyAsyncTask();                 myAsyncTask.execute(3);             }         });          btnStartLongProgress.setOnClickListener(new View.OnClickListener() {             @Override             populace void onClick(View view) {                 btnStartShortProgress.setEnabled(false);                 btnStartLongProgress.setEnabled(false);                 MyAsyncTask myAsyncTask = novel MyAsyncTask();                 myAsyncTask.execute(50);             }         });     }      populace cast MyAsyncTask extends AsyncTask<Integer, Integer, Void> {          @Override         protected Void doInBackground(Integer... integers) {             int i = integers[0];              while(i-- > 0){                 SystemClock.sleep(100);             }              supply null;         }          @Override         protected void onPreExecute() {             progressBar.setVisibility(View.VISIBLE);             contentLoadingProgressBar.show();         }          @Override         protected void onPostExecute(Void aVoid) {             progressBar.setVisibility(View.GONE);             contentLoadingProgressBar.hide();             btnStartShortProgress.setEnabled(true);             btnStartLongProgress.setEnabled(true);         }     } }  

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_margin="20dp"     android:orientation="vertical"     tools:context="com.blogspot.android_er.androidcontentloadingprogressbar.MainActivity">      <TextView         android:id="@+id/title"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center_horizontal"         android:autoLink="web"         android:text="https://rootandroid.org//"         android:textStyle="bold"         />      <Button         android:id="@+id/startshortprogress"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="Start SHORT Progress"/>     <Button         android:id="@+id/startlongprogress"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="Start LONG Progress"/>      <TextView         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="ProgressBar"         android:textStyle="bold"/>     <ProgressBar         android:id="@+id/ProgressBar"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:visibility="gone"/>      <TextView         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:text="ContentLoadingProgressBar"         android:textStyle="bold"/>     <android.support.v4.widget.ContentLoadingProgressBar         android:id="@+id/ContentLoadingProgressBar"         style="?android:attr/progressBarStyle"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:visibility="gone"/>     <ImageView         android:layout_width="match_parent"         android:layout_height="match_parent"         android:src="@mipmap/ic_launcher"/>  </LinearLayout>  

 Examples of ProgressBar too AsyncTask