2

I have a listview with images. The user can click on the thumbnail and a larger image will be download and displayed in an ImageView inside a new activity.

The onclick is inside my GetView in my adapter:

holder.iconImage.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        try{

           //load the image
        String name = folderName.get(position).toString();
        Intent i = new Intent(context, ImageViewLarge.class);
        i.putExtra("link", link);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);


        }
        catch(Exception e){
            Toast.makeText(context, "errror: " + e.toString() , Toast.LENGTH_LONG).show();
        }
    }

});

It can take a few seconds to display the image, so I would like to have either a dialog, or a round progress spinning circle displayed on the screen while the image is loaded.

How can I do this if my onclick is inside my adapter?

I tried this inside the adapter but got an error:

dialog = ProgressDialog.show(context, "Opening Image","Please wait..");

"Unable to add window — token null is not for an application” 
user3437721
  • 2,227
  • 4
  • 31
  • 61
  • That should be the responsibility of ImageViewLarge.class. Because there you are downloading the image I suppose. – greenapps Apr 24 '14 at 11:20

1 Answers1

5

you can use this code it is working fine.

viewHolder.text.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            ProgressDialog dialog = new ProgressDialog(context);
            dialog.setMessage("Please wait.....");
            dialog.show();
            // you can add here  your stuffs
        }
    });
Ajit Kumar Dubey
  • 1,383
  • 1
  • 19
  • 33
  • still get this error when I click on an image in the listview: "android.view.WindowManager$BadTokenException: Unable to add window— token null is not for an application” – user3437721 Apr 24 '14 at 12:31
  • It's working fine in my project.I hope you adapter not getting proper context Use activity context instead of application context. – Ajit Kumar Dubey Apr 24 '14 at 12:33
  • follow this link http://stackoverflow.com/questions/2634991/android-1-6-android-view-windowmanagerbadtokenexception-unable-to-add-window – Ajit Kumar Dubey Apr 24 '14 at 12:33
  • This is how my adapter gets its context: public ImageAdapter(Context c, ArrayList images, ArrayList folderName){ this.context = c; – user3437721 Apr 24 '14 at 12:40
  • and then its called like this: adapter = new ImageAdapter(getApplicationContext(), pix, paths); lstView.setAdapter(adapter); – user3437721 Apr 24 '14 at 12:41
  • yes pass like this- new ImageAdapter(this,pix,paths); – Ajit Kumar Dubey Apr 25 '14 at 05:24