0

I'm using these codes to view an image from my application:

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(imgFile), "image/*");
startActivity(intent);

I have no problem viewing the picture but when the size is a little bit larger, the intent keeps blank until the image is ready to load and show.

My question is, how can I show a ProgressBar, or in more advanced way, show a temporary image, before the real image get shown?

Thanks for the answer.

Kristiono Setyadi
  • 5,635
  • 1
  • 19
  • 29
  • 1
    I thick that when call startActivity(intent), the default image viewer of android is show up, you can't change another app behavior. – xtr Jun 01 '11 at 07:49
  • 1
    Thanks. I was thinking about that too but I hope someone can come up with something like image viewer on Facebook for Android. – Kristiono Setyadi Jun 01 '11 at 11:15

1 Answers1

1

Try Asynctask as shown here:

try{
class test extends AsyncTask{


     TextView tv_per;
     int mprogress;

    Dialog UpdateDialog = new Dialog(ClassContext);

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        mprogress = 0;

        UpdateDialog.setTitle(getResources().getString(R.string.app_name));
        UpdateDialog.setContentView(R.layout.horizontalprogressdialog);
        TextView dialog_message =  (TextView)UpdateDialog.findViewById(R.id.titleTvLeft);
        tv_per = (TextView)UpdateDialog.findViewById(R.id.hpd_tv_percentage);
        dialog_message.setText(getResources().getString(R.string.dialog_retrieving_data));
        dialog_message.setGravity(Gravity.RIGHT);
        UpdateDialog.setCancelable(false);
        UpdateDialog.show();
        super.onPreExecute();
    }



    @Override
    protected void onProgressUpdate(Object... values) {
        // TODO Auto-generated method stub
        ProgressBar update = (ProgressBar)UpdateDialog.findViewById(R.id.horizontalProgressBar);
        update.setProgress((Integer) values[0]);
        int percent =  (Integer) values[0];
        if(percent>=100)
        {
            percent=100;
        }
        tv_per = (TextView)UpdateDialog.findViewById(R.id.hpd_tv_percentage);
         tv_per.setText(""+percent);
    }



    @Override
    protected Object doInBackground(Object... params) {
        // TODO Auto-generated method stub
        //your code of UI operation
}

        super.onPostExecute(result);
        UpdateDialog.dismiss();
    }

 }
 new test().execute(null);

 }
catch(Exception e)
{
 e.printStackTrace();
}

Also refer to this link: Fetch data from server and refresh UI when data is fetched?:)

Community
  • 1
  • 1
Jaydeep Khamar
  • 5,975
  • 3
  • 32
  • 30