ImageSwitcher.setImageURI is not working

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

ImageSwitcher.setImageURI is not working

Postby nico » Wed Jan 09, 2008 7:09 pm

I tried to use ImageSwitcher to load image not from package resource (setImageResource()), but from file in some directory using setImageURI(ContentURI). But it's not working, the image is not displayed. I have supplied the ContentURI with absolute path of the file image.

Any suggestion how to make it works?or any sample code?

Thanks.
nico
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Nov 27, 2007 10:33 am
Location: Indonesia

Top

Postby plusminus » Wed Jan 09, 2008 7:12 pm

Hello nico,

could you provide us some of your code :?:
Easier to help then.

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 nico » Wed Jan 09, 2008 7:23 pm

Here is my code. well,basically i just modify a little (very little :D ) ImageSwitcher1.java from APIDemo, but it became not working :?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. import java.net.URISyntaxException;
  5.  
  6.  
  7.  
  8. import android.app.Activity;
  9.  
  10. import android.net.ContentURI;
  11.  
  12. import android.os.Bundle;
  13.  
  14. import android.util.Log;
  15.  
  16. import android.view.View;
  17.  
  18. import android.view.ViewGroup.LayoutParams;
  19.  
  20. import android.view.animation.AnimationUtils;
  21.  
  22. import android.widget.ImageSwitcher;
  23.  
  24. import android.widget.ImageView;
  25.  
  26. import android.widget.ViewSwitcher;
  27.  
  28.  
  29.  
  30. public class Gambar extends Activity implements ViewSwitcher.ViewFactory {
  31.  
  32.         private ImageSwitcher mSwitcher;
  33.  
  34.  
  35.  
  36.         @Override
  37.  
  38.         public void onCreate(Bundle icicle) {
  39.  
  40.                 super.onCreate(icicle);
  41.  
  42.                 setContentView(R.layout.image_switcher_1);
  43.  
  44.                
  45.  
  46.                 mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
  47.  
  48.                 mSwitcher.setFactory(this);
  49.  
  50.                 mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
  51.  
  52.                                 android.R.anim.fade_in));
  53.  
  54.                 mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
  55.  
  56.                                 android.R.anim.fade_out));
  57.  
  58.                
  59.  
  60.                 showImage();
  61.  
  62.         }
  63.  
  64.  
  65.  
  66.         private void showImage() {
  67.  
  68.                 // TODO Auto-generated method stub
  69.  
  70.                 try {
  71.  
  72.                         mSwitcher.setImageURI(new ContentURI("file:///data/data/com.gambar/files/Tudung01.jpg"));
  73.  
  74.                 } catch (URISyntaxException e) {
  75.  
  76.                         // TODO Auto-generated catch block
  77.  
  78.                         e.printStackTrace();
  79.  
  80.                 }
  81.  
  82.         }
  83.  
  84.  
  85.  
  86.         public View makeView() {
  87.  
  88.                 // TODO Auto-generated method stub
  89.  
  90.                 ImageView i = new ImageView(this);
  91.  
  92.                 i.setBackgroundColor(0xFF000000);
  93.  
  94.                 i.setScaleType(ImageView.ScaleType.FIT_CENTER);
  95.  
  96.                 i.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
  97.  
  98.                                 LayoutParams.FILL_PARENT));
  99.  
  100.                 return i;
  101.  
  102.         }
  103.  
  104. }
  105.  
  106.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


please help... :cry:
nico
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Nov 27, 2007 10:33 am
Location: Indonesia

Postby nico » Wed Jan 09, 2008 9:06 pm

It's solved. Got some help from http://code.google.com/p/android-discovery/
what wrong is I used the word "file://" in argument of ContentURI constructor. i just need to get rid of it :D
nico
Junior Developer
Junior Developer
 
Posts: 19
Joined: Tue Nov 27, 2007 10:33 am
Location: Indonesia

Postby plusminus » Wed Jan 09, 2008 9:21 pm

Grr, just finished todays study and wanted to help you :P

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

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 20 guests