1

我一直在开发 Android RSS 阅读器。我想从 RSS 提要中获取图像并将它们与 RSS 标题一起列出。我已经解析并从“标题”和“描述”标签中获取数据。谁能告诉我如何获取来自“描述”的“src”属性下方的图像URL?

<item>
    <title>Bollywood now more professional, but impersonal: Anupam Kher</title>
    <link>
        http://www.abcd.com/en/node/599
    </link>
    <description>
        <div class=" field field-type-filefield field-field-story-image">
            <div class="field-label">Image:&amp;nbsp;</div>
            <div class="field-items">
                <div class="field-item odd">
                    <img class="imagefield imagefield-field_story_image" width="630" height="420" alt="" src="http://www.madhyamam.com/en/sites/default/files/anumpamkher2.jpg?1334148050" />
                </div>
            </div>
        </div>
        <p>
            <strong>New Delhi: </strong>He has been part of the film industry for almost three decades.
        </p>
        <a href="http://www.abcd.com/en/node/599" target="_blank">read more</a>
    </description>
</item>
4

2 回答 2

1

首先,在AsyncTask. 在此任务中,您可以简单地下载您加载的 HTML/XML 格式的图像。

在后台加载 URL 时,可以调用以下例程:

private Bitmap getImageFromURL(URL imgUrl){
        Bitmap bmp = null;

        try {
            HttpURLConnection conn= (HttpURLConnection)imgUrl.openConnection();
            conn.setDoInput(true);
            conn.connect();
            InputStream is = conn.getInputStream();

            bmp = BitmapFactory.decodeStream(is);
       } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
       }
       return bmp;  
    }
于 2012-06-02T20:15:38.823 回答
-1

我找到了解决方案......

                        News news=new News();    

                        String img  = news.Description[i];
                        String cleanUp = img.substring(0, img.indexOf(">")+1);
                        img = img.substring(img.indexOf("src=") + 5);
                        int indexOf = img.indexOf("'");
                            if (indexOf==-1){
                            indexOf = img.indexOf("\"");
                           }
                        img = img.substring(0, indexOf);
                        news.image[i]=img;
于 2012-04-12T07:43:19.743 回答