开发者

How to view images in an app from a server?

I am making an app that will have images. When the user hits the next button the app will display the next image.

Would this be done with a server that will host the images and when the next button is hit the image in that server will go to the app,

How can i do this.

EXAMPLE OF APP IDEA...

App1

Button1 = Previous

Button2 = Next

SERVER/HOST

Image1

Image2

Image3

Image4


When button2 (NEXT) is clicked it will display Image2 from server

When Button2 (NEXT) is clicked AGAIN it will display Image3 from server

-BUT-

When Button1 (Previous) is clicked it will display the previous image (开发者_Go百科e.g. Image2)

-

Sincerely,

IntelSoftApps

intelsoftandroid@gmail.com

IntelSoftApps.com


    /***********************************************************
     * This method will return the image from a URL. We will input 
     * the item image URL.
     ***********************************************************/
    public Drawable getRemoteImage(final URL aURL) {
        try {
             final URLConnection conn = aURL.openConnection();
             conn.connect();
             final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
             final Drawable d = Drawable.createFromStream(bis, "src");
             bis.close();
             return d;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
   }

You should make this method call from a seperate thread so as to not freeze the ui while its getting the picture. Once you have your image as a Drawable you just have to set an ImageView to display it.

imageView.setImageDrawable(myImage); 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜