How to show image on gallery with unfix path?

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

How to show image on gallery with unfix path?

Postby sonicbloom » Sun Aug 30, 2009 12:27 pm

Hi Everyone,
I would to show image on Gallery. but i want show with unfix path of image because i get path of image from XML file.

Who have to idea ? i very serious !!!!! help me please!

regard,
sonicbloom.
... EverythinG that has a Beginning has an EnD ...
sonicbloom
Freshman
Freshman
 
Posts: 4
Joined: Tue Jun 16, 2009 6:32 pm
Location: Thailand

Top

Postby sonicbloom » Sun Aug 30, 2009 4:22 pm

Hi, this my code : i want to show on GridView but i try to show an ImageView. my result is TextView is path of image from XML file and ImageView to show Image from last tag from XML file only.

i would like to show Image all tag from XML file, now i out of idea !!! Help me please!!

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class XML extends Activity  {
  3.  
  4.         public ImageView imgV;
  5.  
  6.         public TextView tv;
  7.  
  8.         public XML myXML;
  9.  
  10.         public String str;
  11.  
  12.         private final String url = "http://192.168.1.57:80/test/Movies.xml";
  13.  
  14.         private final String MY_DEBUG = "SHOW POSTER ERROR!!";
  15.  
  16.         GridView mGrid;
  17.  
  18.     public void onCreate(Bundle savedInstanceState) {
  19.  
  20.         super.onCreate(savedInstanceState);
  21.  
  22.         setContentView(R.layout.main);
  23.  
  24.        
  25.  
  26.         //setContentView(R.layout.grid1);
  27.  
  28.         //mGrid = (GridView) findViewById(R.id.mygrid);
  29.  
  30.         //mGrid.setAdapter(mGrid.getAdapter());
  31.  
  32.         //mGrid.setAdapter(new ImageAdapter());
  33.  
  34.         imgV = (ImageView) findViewById(R.id.imgv);
  35.  
  36.         tv = (TextView) findViewById(R.id.tv);
  37.  
  38.         try {
  39.  
  40.                         this.Parsed(url);
  41.  
  42.                 } catch (Exception e) {
  43.  
  44.                         e.printStackTrace();
  45.  
  46.                 }
  47.  
  48.     }
  49.  
  50.    
  51.  
  52.     public void getPoster(String aUrl) {
  53.  
  54.         //ImageView imgV = new ImageView(XML.this);
  55.  
  56.        
  57.  
  58.                 try{
  59.  
  60.                         URL url = new URL(aUrl);
  61.  
  62.                         URLConnection conn = url.openConnection();
  63.  
  64.                         conn.connect();
  65.  
  66.                         InputStream is = conn.getInputStream();
  67.  
  68.                         BufferedInputStream bis = new BufferedInputStream(is);
  69.  
  70.                         Bitmap bm = BitmapFactory.decodeStream(bis);
  71.  
  72.                         is.close();
  73.  
  74.                         bis.close();
  75.  
  76.                         //this.imgV.setLayoutParams(new Gallery.LayoutParams(145, 145));
  77.  
  78.                         imgV.setAdjustViewBounds(false);
  79.  
  80.                         imgV.setScaleType(ImageView.ScaleType.FIT_CENTER);
  81.  
  82.                         imgV.setPadding(3, 3, 3, 3);
  83.  
  84.                         imgV.setImageBitmap(bm);
  85.  
  86.                 }catch(Exception e) {
  87.  
  88.                         this.imgV.setImageDrawable(getResources().getDrawable(R.drawable.dunno));
  89.  
  90.                 }
  91.  
  92.        
  93.  
  94.     }
  95.  
  96.    
  97.  
  98.     public void Parsed(String aurl) throws Exception {
  99.  
  100.         URL url = new URL(aurl);
  101.  
  102.         SAXParserFactory spf = SAXParserFactory.newInstance();
  103.  
  104.         SAXParser sp = spf.newSAXParser();
  105.  
  106.         DefaultHandler dHandler = new DefaultHandler() {
  107.  
  108.                 boolean name, detail, poster;
  109.  
  110.                 public void startElement(String uri, String localName, String qName, Attributes attr)throws SAXException {
  111.  
  112.                         if(localName.equals("name")) {
  113.  
  114.                                 name = true;
  115.  
  116.                         }
  117.  
  118.                         if(localName.equals("detail")) {
  119.  
  120.                                 detail = true;
  121.  
  122.                         }
  123.  
  124.                         if(localName.equals("poster")) {
  125.  
  126.                                 poster = true;
  127.  
  128.                         }
  129.  
  130.                 }
  131.  
  132.                 public void characters(char[] ch, int start, int len) {
  133.  
  134.                         str = new String(ch, start, len);
  135.  
  136.                         if(name) {
  137.  
  138.                                 name = false;
  139.  
  140.                         }
  141.  
  142.                         if(detail) {
  143.  
  144.                                 detail = false;
  145.  
  146.                         }
  147.  
  148.                         if(poster) {
  149.  
  150.                                 tv.append("U R : " + str + "\n");
  151.  
  152.                                 //tv.setText("fdfsdfsfsfdsfdsfsfsdfdsfdsdsfsdf");
  153.  
  154.                                 //mPoster = str;
  155.  
  156.                                 getPoster(str);
  157.  
  158.                                 //mGrid.setAdapter(new ImageAdapter());
  159.  
  160.                                 poster = false;
  161.  
  162.                         }
  163.  
  164.                 }
  165.  
  166.         };
  167.  
  168.         sp.parse(aurl, dHandler);
  169.  
  170.     }
  171.  
  172. }
  173.  
  174.  
Parsed in 0.042 seconds, using GeSHi 1.0.8.4


Regards,
sonicbloom
... EverythinG that has a Beginning has an EnD ...
sonicbloom
Freshman
Freshman
 
Posts: 4
Joined: Tue Jun 16, 2009 6:32 pm
Location: Thailand

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: Exabot [Bot], Google Feedfetcher and 4 guests