开发者

Toast and Image not shown

开发者 https://www.devze.com 2023-03-14 01:53 出处:网络
The thing is like this. I have a zip file with images that uncompressing in the background (using a Thread) I start a new Activity from my main one to show these images. To show the f开发者_Go百科irst

The thing is like this. I have a zip file with images that uncompressing in the background (using a Thread) I start a new Activity from my main one to show these images. To show the f开发者_Go百科irst image I call this function on onResume:

public boolean showImage(String validFile){
    File page = new File(validFile);
    System.err.println("Attempting to show " + validFile);
    boolean found = false;
    if (page.exists()){
        System.err.println("Page exist");
        found = true;
    }
    else{           
        System.err.println("Page does not exist");
        long start = System.currentTimeMillis();
        //ProgressDialog loading = ProgressDialog.show(this, "", "Loading....",true);
        Toast.makeText(this, "Loading...", Toast.LENGTH_LONG);
        while (((System.currentTimeMillis() - start) < 5000) && (!found)){              
            if (page.exists()){
                found = true;
                //t.cancel();
                System.err.println("Page found");
            }
            else{
                System.err.println("Page does not exist");
            }
        }
    }       
    if (!found){
        return false;
    }
    else{
        System.err.println("Setting up image");
        ims.setImageDrawable(new  BitmapDrawable(BitmapFactory.decodeFile(validFile)));
        return true;
    }       
}

All I want to do is to show a Toast a progress dialog or something that says Loading... while the first image uncompresses. However neither the toast or the image are shown. Now I know the image is there for two reasons: 1 the Setting up Image and File found messages appear and I can use fling to move through the images and work just fine.

This is what happens. My activity starts and enters the code above but the first image is never shown. I fling and see the second image and the third and so forth.

So what am I doing wrong?

Thanks for any help!


There might be another issue besides this, but the toast will not appear if you don't call the show() method:

Toast.makeText(this, "Loading...", Toast.LENGTH_LONG).show();
0

精彩评论

暂无评论...
验证码 换一张
取 消