Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display a custom loading bar in a dialog box in android
    primarykey
    data
    text
    <p>I have an app that lets the user select a <em>radio-button</em> from a <em>list</em>. When the <em>radio-button</em> is selected, a custom dialog appears looking like this: <img src="https://i.stack.imgur.com/zX8j6.png" alt="enter image description here"></p> <p>I want to display a animation that shows a hamster running while the actual image is downloaded using an aynctask class. After the requested image is finished downloading, it should be displayed on the screen(replacing the hamster animation).</p> <p>So, my question is: how can can I achieve this? I tried using the gif frame loader, but that doesn't work in the dialog, however, I can display a rotating image, but I want the loading bar to be a little more fun, so I chose the running hamster. The above methods are from <a href="http://yekmer.posterous.com/how-to-make-a-loading-animator-in-android" rel="nofollow noreferrer">here</a></p> <p>Also, the user should be able to click the close button, even though the image hasn't loaded(in case the image url is broken).</p> <p><strong>Edit:</strong> This is the example that doesn't work:</p> <pre><code>import android.app.Activity; import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; public class MainActiviy extends Activity implements OnClickListener{ Button start, stop; ImageView imageView; AnimationDrawable frameAnimation; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); imageView = (ImageView)findViewById(R.id.blankImageView); start = (Button)findViewById(R.id.start); stop = (Button)findViewById(R.id.stop); imageView.setBackgroundResource(R.drawable.spin_animation); frameAnimation = (AnimationDrawable) imageView.getBackground(); start.setOnClickListener(this); stop.setOnClickListener(this); //does not start the animation frameAnimation.start(); } public void onClick(View v) { switch(v.getId()) { case R.id.start: frameAnimation.start(); break; case R.id.stop: frameAnimation.stop(); break; } } } </code></pre> <p>//the main.xml layout</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;ImageView android:layout_width="wrap_content" android:id="@+id/blankImageView" android:layout_height="wrap_content"/&gt; &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/start" android:text="start"/&gt; &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/stop" android:text="stop"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>//the spin_animation.xml file in the res/drawable folder</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:oneshot="false"&gt; &lt;item android:drawable="@drawable/frame1" android:duration="60" /&gt; &lt;item android:drawable="@drawable/frame2" android:duration="60" /&gt; &lt;item android:drawable="@drawable/frame3" android:duration="60" /&gt; &lt;item android:drawable="@drawable/frame4" android:duration="60" /&gt; &lt;/animation-list&gt; </code></pre> <p>//and the <a href="http://www.2shared.com/file/scyqZKSm/frames.html" rel="nofollow noreferrer">frames</a> </p> <p>How can I make the image animate without clicking the start button?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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