Вопрос

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” 
Это было полезно?

Решение

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
        }
    });
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top