2012-01-27 9 views
0

RSSフィードからイメージを取得してlistviewに表示する方法を教えてください。私のすべてが動作しています...しかし、イメージフォームのURLを取得することができません..私はイメージのための関数を書いてもlode ..しかし、使用するためのURL文字列を取ることができません。私はURLを表示することはできますが。 私が試したコード..イメージフォームを取得する方法RSSフィードとストアintリストビュー?

public class RssFeedExampleTestImageActivity extends ListActivity 
{ 
    private ArrayList<RSSIteam> itemlist = null; 
    private RSSListAdaptor rssadaptor = null; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 

     itemlist = new ArrayList<RSSIteam>(); 
     new RetrieveRSSFeeds().execute(); 

     RSSListAdaptor adapter = new RSSListAdaptor(this, R.layout.main, itemlist); 
     setListAdapter(adapter); 
    } 

    //Function for loading image from web 
    public static Drawable LoadImageFromWeb(String uri) 
    { 
     try 
     { 
      InputStream is = (InputStream) new URL(uri).getContent(); 
      Drawable d = Drawable.createFromStream(is, "src name"); 
      return d; 

     } 
     catch (Exception e) 
     { 
      return null; 
     } 
    } 

    private void retrieveRSSFeed(String urlToRssFeed,ArrayList<RSSIteam> list) 
    { 
     try 
     { 
      URL url = new URL(urlToRssFeed); 
      SAXParserFactory factory = SAXParserFactory.newInstance(); 
      SAXParser parser = factory.newSAXParser(); 
      XMLReader xmlreader = parser.getXMLReader(); 

      RSSParser theRssHandler = new RSSParser(list); 

      xmlreader.setContentHandler(theRssHandler); 

      InputSource is = new InputSource(url.openStream()); 

      xmlreader.parse(is); 
     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 
    } 

    private class RetrieveRSSFeeds extends AsyncTask<Void, Void, Void> 
    { 
     private ProgressDialog progress = null; 

     @Override 
     protected Void doInBackground(Void... params) 
     { 
      /*RSSIteam data = null; 
      Uri custuri = Uri.parse(data.imageurl); 
      String str = custuri.toString(); 
      LoadImageFromWeb(str); 
      */ 
      retrieveRSSFeed("http://some_url",itemlist); 

      rssadaptor = new RSSListAdaptor(RssFeedExampleTestImageActivity.this, R.layout.customlist, itemlist); 
      return null; 
     } 

     @Override 
     protected void onCancelled() 
     { 
      super.onCancelled(); 
     } 

     @Override 
     protected void onPostExecute(Void result) 
     { 
      setListAdapter(rssadaptor); 

      progress.dismiss(); 
      super.onPostExecute(result); 
     } 

     @Override 
     protected void onPreExecute() 
     { 
      progress = ProgressDialog.show(RssFeedExampleTestImageActivity.this, null, "Loading RSS Feeds..."); 
      super.onPreExecute(); 
     } 

     @Override 
     protected void onProgressUpdate(Void... values) 
     { 
      super.onProgressUpdate(values); 
     } 
    } 

    private class RSSListAdaptor extends ArrayAdapter<RSSIteam> 
    { 
     private List<RSSIteam> objects = null; 

     public RSSListAdaptor(Context context, int textViewResourceId, List<RSSIteam> objects) 
     { 
      super(context, textViewResourceId, objects); 
      this.objects = objects; 
     } 

     @Override 
     public View getView(int position, View convertView, ViewGroup parent) 
     { 
      View view = convertView; 


      if(null == view) 
      { 
        LayoutInflater vi = (LayoutInflater)RssFeedExampleTestImageActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        view = vi.inflate(R.layout.customlist, null); 
      } 

      RSSIteam data = objects.get(position); 

      if(null != data) 
      { 
       Drawable imgLoad = null; 
        TextView title = (TextView)view.findViewById(R.id.txtViewTitle); 
        TextView description = (TextView)view.findViewById(R.id.txtViewDescription); 
        TextView imagetxt = (TextView)view.findViewById(R.id.txtViewImageUrl); 

        ImageView imageLoge = (ImageView)view.findViewById(R.id.imgViewLogo); 

        title.setText(data.title); 
        description.setText(data.description); 
        imagetxt.setText(data.imageurl); 
        /*imageLoge.setVisibility(View.VISIBLE); 
        imageLoge.setBackgroundDrawable(imgLoad);*/ 



      } 
      return view; 
     } 
    } 
} 

答えて

関連する問題