开发者

View images from a website in app?

In my android app I have to see the images from a certain website. On this website the images are sorted in certain categories and can be voted. I my app I should see (when I select a category) all the pictures from that category and the votes for each picture.

I have never done something like this and I have no 开发者_StackOverflow社区idea how to start this. Can anyone give me some idea? any idea is welcome..

Thanks in advance.


First, you should try to retrieve a list of images you have to display. It can be accomplished by retrieving the page of the wanted category on the website (see http://developer.android.com/reference/org/apache/http/client/methods/HttpGet.html) and then parsing it (you can use may ways for that, I let you choose the one you want to apply).

The next step, in my opinion, is to create a custom adapter in order to keep your data. So, create a class which extends BaseAdapter, and manage to make it contain a list of Drawable (ArrayList<Drawable>) and a list of URLs (ArrayList<String>). Also, provide a method which allows you to add an URL to the adapter.

When an URL is added, create a new Thread (or AsyncTask) which will retrieve the image (in order to do that use HttpGet here too) and create a Drawable (using Drawable.createFromStream). Once the download is done, notify an Handler which will add the URL to your ArrayList<String>, and the Drawable you have created in the Thread to your ArrayList<Drawable>. Don't forget synchronization if you use this method.

Once your adapter is complete, use the method you want to display its content. You could, for example, use the Gallery view (see http://developer.android.com/guide/tutorials/views/hello-gallery.html).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜