Update ImageSwither to pull from URL?

Put your problem here if it does not fit any of the other categories.

Update ImageSwither to pull from URL?

Postby ryank » Mon Jan 28, 2008 5:12 am

I am trying to update the ImageSwither app to pull its images from a URL. I am able to update the thumbnails since it is using an
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ImageView
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
where I can call
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. setImageBitmap(bitmap)
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
, but I want those images to be displayed larger when selected.

Here is some updated code I tried but it doesn't work.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onItemSelected(AdapterView parent, View v, int position, long id) {
  2.  
  3.         //mSwitcher.setImageResource(mImageURLIds[position]);
  4.  
  5.         mSwitcher.setImageURI(ContentURI.create(mImageURLIds[position]));
  6.  
  7.     }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

I also tried the code (similar to what was used in the weatherforecast) in the
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. onItemSelected
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
method, but I'm not sure how to tell the gallery to use that image.

Sorry if this doesn't make sense, but I just started using Android and am in learning mode right now.

Thanks!
User avatar
ryank
Developer
Developer
 
Posts: 43
Joined: Mon Jan 28, 2008 3:23 am

Top

Postby plusminus » Mon Jan 28, 2008 3:18 pm

Hello ryank,

what type and content is your mImageURLIds-Array :?:

The code from the WeatherForecast worked pretty well, you could do sth like this (code without syntax-errors, but not live tested):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 ImageSwitcher is = new ImageSwitcher(this); // or findViewbyId, whatever you have in your code...
  2.  
  3.                 try {
  4.                         URL aURL = new URL("http://www.anddev.org/favicon.ico");
  5.  
  6.                         URLConnection conn = aURL.openConnection();
  7.                         conn.connect();
  8.                         InputStream in = conn.getInputStream();
  9.                         BufferedInputStream bis = new BufferedInputStream(in);
  10.                         Bitmap bm = BitmapFactory.decodeStream(bis);
  11.                         bis.close();
  12.                         in.close();
  13.                         BitmapDrawable bmd = new BitmapDrawable(bm);
  14.                         is.setImageDrawable(bmd);
  15.                 } catch (Exception e) {
  16.                         Log.e("DEBUGTAG", "Error",e);
  17.                 }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby ryank » Mon Jan 28, 2008 4:04 pm

Thanks plusminus! I will try when I get home.

Was I on the right track as far as putting that code in the onItemSelected() method?

Thanks again, and I will let you know how it goes!
User avatar
ryank
Developer
Developer
 
Posts: 43
Joined: Mon Jan 28, 2008 3:23 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google Feedfetcher and 17 guests