1

以下の xml フィードがあります。

<Categories>
 <Category name="Title 1"
 <Article>
  <article title="subtitle 1"  id="1" >
   <thumb_image>
   <image url="http://forfeed.jpeg"/></thumb_image>
    <images>
    <image url="http://ad_thumb.jpg"/>
      </images>
     </article>
  <article title="subtitle 2"  id="2" >
     <image url="http://forfeed.jpeg"/></thumb_image>
      <images>
    <image url="http://ad_thumb.jpg"/>
      </images>
    </article>
 </Article>
  </Category>
  <Category name="Title 2"
  <Articles>
  <article title="subtitle 4"  id="4" >
    <image url="http://forfeed.jpeg"/></thumb_image>
      <images>
    <image url="http://ad_thumb.jpg"/>
      </images>
    </article>
  <article title="subtitle 5"  id="5" >
  <image url="http://forfeed.jpeg"/></thumb_image>
  <images>
    <image url="http://ad_thumb.jpg"/>
      </images>
    </article>
 </Articles>
 </Category>

これは私のハンドラクラスです:

  public void startElement(String uri, String localName, String qName,Attributes attributes) throws SAXException {
   currentElement = true;
   if (localName.equals("Categories"))
     {
     sitesList = new SitesList();
    }
   ------------------------
     ---------------------
      ---------------------
      else if (localName.equals("thumb_image")) {
           ImageList ImageList = new ImageList();
       n++;
          isThumbURL = true;
               } 
          else if (localName.equals("image")) {
           if (isThumbURL)
          {

          String attr = attributes.getValue("url");
            sitesList.setImageURL(attr);
            String Sub_arry=n+attr;
             Appscontent.Sub_arraylist.add(Sub_arry);

                 }}}

私の主な活動では、画像を設定する必要があります:

im.setImageBitmap(Appscontent.Sub_arraylistimage);

これらの行で次のエラーが発生しています。

ImageView 型のメソッド setImageBitmap(Bitmap) は、引数 (ArrayList) には適用されません。

これらのエラーを解決するにはどうすればよいですか。助けてください...

編集:

私のxmlフィードでは、thumb_imageタグだけから画像のURLを取得するにはどうすればよいですか...しかし、これらのコードでは、thumb_imageとimagesタグの両方から画像のURLを取得しています..これらの条件をどのように記述できますか...

4

2 に答える 2

0

このエラーは、arraylist を imageview に設定しようとしているために発生していますが、image view はビットマップを表示する必要があるため、次のようにする必要があります。

im.setImageBitmap(Appscontent.Sub_arraylistimage.get(0));

しかし、これは画像のURLを受け取るので、下のリンクをチェックしてURLから画像をロードしてください

URLまたはこのURLから画像を表示

于 2013-03-02T06:49:52.800 に答える
0

画像の URL をビットマップに変換し、そのビットマップを imageView に設定する必要があります。

URL から画像を読み込むには、さまざまな方法があります。画像をロードする効率的な方法は、バックグラウンド スレッドで実行することです。UI スレッドで画像をロードしようとすると、UI スレッドがハングし、4.0 以上の Android OS では NetworkOnMainTHread Excpetion でクラッシュします。それらのいずれかを試すことができます:

1.ユニバーサル イメージローダー: https://github.com/nostra13/Android-Universal-Image-Loader

2.Fedor のレイジー ローダー: https://github.com/thest1/LazyList

3. http://android-developers.blogspot.in/2010/07/multithreading-for-performance.html

于 2013-03-02T06:50:27.427 に答える