0

I am loading a textview value and and image view at runtime using asychtask and it takes time and I don't want to show the progressDialog on the whole screen. Instead I want a small progress bar in the place of textview and image view. How can I achieve the same. Is it possible?? In some apps I have seen the same.

Thanks

Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
  • Yes, it is possible. Refer to these links: http://androiddesk.wordpress.com/tag/progress-dialog-with-an-example/ , http://www.mkyong.com/android/android-progress-bar-example/ , http://tausiq.wordpress.com/2012/08/07/android-progress-dialog-example/ – MysticMagicϡ Nov 19 '12 at 07:40

2 Answers2

1

Yes you can use Custom Dialog that extends Dialog class

import android.app.Dialog;
import android.content.Context;
import android.widget.ProgressBar;
import android.widget.RelativeLayout.LayoutParams;



public class MyProgressDialog extends Dialog {

    public static MyProgressDialog show(Context context, CharSequence title,
            CharSequence message) {
        return show(context, title, message, false);
    }

    public static MyProgressDialog show(Context context, CharSequence title,
            CharSequence message, boolean indeterminate) {
        return show(context, title, message, indeterminate, false, null);
    }

    public static MyProgressDialog show(Context context, CharSequence title,
            CharSequence message, boolean indeterminate, boolean cancelable) {
        return show(context, title, message, indeterminate, cancelable, null);
    }

    public static MyProgressDialog show(Context context, CharSequence title,
            CharSequence message, boolean indeterminate,
            boolean cancelable, OnCancelListener cancelListener) {
        MyProgressDialog dialog = new MyProgressDialog(context);
        dialog.setTitle(title);

        dialog.setCancelable(cancelable);
        dialog.setOnCancelListener(cancelListener);
        /* The next line will add the ProgressBar to the dialog. */
        dialog.addContentView(new ProgressBar(context), new LayoutParams(40,40));
        dialog.show();

        return dialog;
    }

    public MyProgressDialog(Context context) {
        super(context, R.style.NewDialog);
    }
}

In your Activity simply call like this to show:

 MyProgressDialog dialog=MyProgressDialog.show(this, null,null);

to dismiss also as usual dialog.dismiss(). You can specify attributes in style.xml

Abhi
  • 8,935
  • 7
  • 37
  • 60
  • I think you have not understood me bro. I just want to show the progress dialog only in the place of TextView ( small ) as it is in the case of lazy image loading – Gaurav Arora Nov 19 '12 at 07:40
  • Bro I want to like it,. this thing is ok.. but i dont want to show it for the whole page. I want to show it only for a single textview and an imageview till it gets loaded from the asynchtask. Now understand – Gaurav Arora Nov 19 '12 at 07:43
  • okay then use Prograss bar in xml it self where you want show. then you can play with Visible and Gone – Abhi Nov 19 '12 at 07:46
1

This is what you can do. ProgressBar can be added as view in the layout so just add this as view on top of your image view and text view (Using say FrameLayout) and once you have the data you can set the visibility of the ProgressView to INVISIBLE or GONE.

The javadoc page of ProgressBar also has code sample that you can use use.

Praful Bhatnagar
  • 7,425
  • 2
  • 36
  • 44