Android. Yor own progress-bar?

1.6k views Asked by At

4th hour of searching and No results all the same. A fact that we should not. Tell me how to implement the following:

  1. There AsyncTask that performs certain actions
  2. There are 25 pictures of the following form: Image enter image description here
  3. There Sheet Animation xml:

     <animation-list
             xmlns:android="http://schemas.android.com/apk/res/android"
             android:oneshot="true"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content">
             <item android:drawable="@drawable/a1" android:duration="250"/>
             <item android:drawable="@drawable/a2" android:duration="250"/>
             <item android:drawable="@drawable/a3" android:duration="250"/>
             <item android:drawable="@drawable/a4" android:duration="250"/>
             <item android:drawable="@drawable/a5" android:duration="250"/>
             <item android:drawable="@drawable/a6" android:duration="250"/>
             <item android:drawable="@drawable/a7" android:duration="250"/>
             <item android:drawable="@drawable/a8" android:duration="250"/>
             <item android:drawable="@drawable/a9" android:duration="250"/>
             <item android:drawable="@drawable/a10" android:duration="250"/>
             <item android:drawable="@drawable/a11" android:duration="250"/>
             <item android:drawable="@drawable/a12" android:duration="250"/>
             <item android:drawable="@drawable/a13" android:duration="250"/>
             <item android:drawable="@drawable/a14" android:duration="250"/>
             <item android:drawable="@drawable/a15" android:duration="250"/>
             <item android:drawable="@drawable/a16" android:duration="250"/>
             <item android:drawable="@drawable/a17" android:duration="250"/>
             <item android:drawable="@drawable/a18" android:duration="250"/>
             <item android:drawable="@drawable/a19" android:duration="250"/>
             <item android:drawable="@drawable/a20" android:duration="250"/>
             <item android:drawable="@drawable/a21" android:duration="250"/>
             <item android:drawable="@drawable/a22" android:duration="250"/>
             <item android:drawable="@drawable/a23" android:duration="250"/>
             <item android:drawable="@drawable/a24" android:duration="250"/>
             <item android:drawable="@drawable/a25" android:duration="250"/>
             </animation-list>
    
    • There xml markup:
  <RelativeLayout
  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" >
      <ImageView
          android:id="@+id/image"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="bottom|left|right|top"
          android:layout_margin="50dp" /> </RelativeLayout>

how to get in AsyncTask in a method:

protected void onProgressUpdate(Integer... progress) { }

Work progress bar is not infinite but only when loading data into AsynkTask.

Sometimes it happens that the data have already boot animation and is still going on or no turnover data and the animation is over.

Please tell me how to solve this problem. For earlier thanks to all who respond!

1

There are 1 answers

0
user3068658 On

Something like this, but this code displays me why that normal progressbar dialog/

public class MainActivity extends Activity {
    private static final String TAG = "MyApp";
    private ProgressDialog progressDialog;
    Button buttonStart;
    public String a;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        buttonStart = (Button) findViewById(R.id.buttonStart);   

    }
    public void onclick(View v) {
        new MyTask().execute();
    }

    class MyTask extends AsyncTask<String, Integer, Void> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            buttonStart.setVisibility(View.INVISIBLE);
            progressDialog = new ProgressDialog(MainActivity.this);
            progressDialog.setCancelable(true);
            progressDialog.setProgressDrawable(getResources().getDrawable(R.drawable.a1));
            progressDialog.show();
        }
        @Override
        protected Void doInBackground(String... urls) {
           for (int i = 1; i < 25; i ++) {
                a = "a" + i;
            }
            return null;
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);       
            Resources res = getResources();
            int myId = res.getIdentifier(a, "drawable", "app.pogress");
            Drawable d = res.getDrawable(myId);
            progressDialog.setProgressDrawable(getResources().getDrawable(R.drawable.a1));
            progressDialog.setProgressDrawable(d);
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);

        }


    }


}

Where is the mistake?