0

I need a way to show "loading" image near text view. In my app, some data receives from server periodically and while these processes executing I need to show to user loading(wait) image like this image below.

sample image http://img685.imageshack.us/img685/1403/androidwait.png

Then, when executing finished, I want loading image to disappear from screen. Some time later when asyn task start to receive some data again. This image will show again. This all process will go periodically. I don't use ProgressDialog. Because it cover all screen and keep user waiting.

Important point: when image disappeared, its area in layout will used by text view and no blank will be there.

svick
  • 236,525
  • 50
  • 385
  • 514
Gürcan Kavakçı
  • 562
  • 1
  • 11
  • 24

3 Answers3

4

Why not to use ProgressBar? http://developer.android.com/reference/android/widget/ProgressBar.html

You can inflate it anywhere inside your main UI and operate it with progressBar.setVisibility(View.GONE) and progressBar.setVisibility(View.VISIBLE).

Please don't forget to do it ONLY in main UI thread. So either use AsyncTask's onPostExecute, or wrap execution with activity.runOnUiThread(Runnable).

Note: ProgressBar in Android can have 2 states: either horizontal with progress, or just rotating circle, just like on your screenshot. Default is 2nd, so just what you want.

Good luck

AlexN
  • 2,544
  • 16
  • 13
  • I don't use ProgressBar, because there will be more than one wait image. – Gürcan Kavakçı Sep 02 '12 at 18:11
  • "rotating circle" solution can be use, I will think it. – Gürcan Kavakçı Sep 02 '12 at 18:14
  • Note, you can always provide any custom animated drawable to ProgressBar, so if you just don't like default "rotating circle" - check this thread for details. http://stackoverflow.com/questions/2819778/custom-drawable-for-progressbar-progressdialog – AlexN Sep 02 '12 at 18:20
1

This tutorial is answer of my question. When we apply this xml code where we want to show rotating circle progress bar in layout,

<ProgressBar
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         style="@android:style/Widget.ProgressBar.Small"
         android:layout_marginRight="5dp" />

it seems just I want.

And then using java code to start and stop it.

Gürcan Kavakçı
  • 562
  • 1
  • 11
  • 24
  • I'm interested by your tutorial but the url you gave `http://example.com` is wrong, do you still have it? – jolivier Oct 20 '12 at 14:26
  • @jolivier, you right, url is broken. Sorry now i can't remember which was this tutorial is. If i find it's url again, i will update it. – Gürcan Kavakçı Nov 02 '12 at 18:31
  • no problem, I understood in the mean time that ProgressBar handles also the rotating circle despite its name. So i found a solution. – jolivier Nov 02 '12 at 21:58
0

You can place an imageview then in asyntask

onPreExecute(){//Imageview gets set visible here}

onPostExecute(){//Turn imageview off here}

Infinity
  • 3,695
  • 2
  • 27
  • 35
  • 1
    You can set layout weight and layout width for textview and imageview in postExecute. So you can take advantage of that for dynamic layout resizing. – Infinity Sep 02 '12 at 18:15