Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I made a sample code like below.. I hope that my codes help you :)</p> <p>[main.xml]</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" &gt; &lt;Button android:id="@+id/wheel_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/icon_spin_animation" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>[icon_spin_animation.xml]</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/selected" android:oneshot="false"&gt; &lt;item android:drawable="@drawable/wheel_db_update01" android:duration="50"/&gt; &lt;item android:drawable="@drawable/wheel_db_update02" android:duration="50"/&gt; &lt;item android:drawable="@drawable/wheel_db_update03" android:duration="50"/&gt; &lt;item android:drawable="@drawable/wheel_db_update04" android:duration="50"/&gt; &lt;item android:drawable="@drawable/wheel_db_update05" android:duration="50"/&gt; &lt;item android:drawable="@drawable/wheel_db_update06" android:duration="50"/&gt; &lt;/animation-list&gt; </code></pre> <p>[Activity Code]</p> <pre><code>public class ProgressOnTheButtonActivity extends Activity implements OnClickListener { /** Called when the activity is first created. */ AnimationDrawable mFrameAnimation = null; boolean mbUpdating = false; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btnWheel = (Button)findViewById(R.id.wheel_button); btnWheel.setOnClickListener(this); mFrameAnimation = (AnimationDrawable) btnWheel.getBackground(); } public void onClick(View v) { if(v.getId() == R.id.wheel_button) { if(!mbUpdating) { mbUpdating = true; new AsyncTaskForUpdateDB().execute(""); } } } private class AsyncTaskForUpdateDB extends AsyncTask&lt;String, Integer, ResultOfAsyncTask&gt; { @Override protected void onPreExecute() { mFrameAnimation.start(); super.onPreExecute(); } @Override protected ResultOfAsyncTask doInBackground(String... strData) { ResultOfAsyncTask result = new ResultOfAsyncTask(); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } return result; } @Override protected void onPostExecute(ResultOfAsyncTask result) { mFrameAnimation.stop(); mbUpdating = false; } @Override protected void onCancelled() { mFrameAnimation.stop(); mbUpdating = false; super.onCancelled(); } @Override protected void onProgressUpdate(Integer... progress) { } } private class ResultOfAsyncTask { int iErrorCode = 0; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload