public class XML extends Activity {
public ImageView imgV;
public TextView tv;
public XML myXML;
public String str;
private final String url = "http://192.168.1.57:80/test/Movies.xml";
private final String MY_DEBUG = "SHOW POSTER ERROR!!";
GridView mGrid;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//setContentView(R.layout.grid1);
//mGrid = (GridView) findViewById(R.id.mygrid);
//mGrid.setAdapter(mGrid.getAdapter());
//mGrid.setAdapter(new ImageAdapter());
imgV = (ImageView) findViewById(R.id.imgv);
tv = (TextView) findViewById(R.id.tv);
try {
this.Parsed(url);
} catch (Exception e) {
e.printStackTrace();
}
}
public void getPoster(String aUrl) {
//ImageView imgV = new ImageView(XML.this);
try{
URL url = new URL(aUrl);
URLConnection conn = url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap bm = BitmapFactory.decodeStream(bis);
is.close();
bis.close();
//this.imgV.setLayoutParams(new Gallery.LayoutParams(145, 145));
imgV.setAdjustViewBounds(false);
imgV.setScaleType(ImageView.ScaleType.FIT_CENTER);
imgV.setPadding(3, 3, 3, 3);
imgV.setImageBitmap(bm);
}catch(Exception e) {
this.imgV.setImageDrawable(getResources().getDrawable(R.drawable.dunno));
}
}
public void Parsed(String aurl) throws Exception {
URL url = new URL(aurl);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
DefaultHandler dHandler = new DefaultHandler() {
boolean name, detail, poster;
public void startElement(String uri, String localName, String qName, Attributes attr)throws SAXException {
if(localName.equals("name")) {
name = true;
}
if(localName.equals("detail")) {
detail = true;
}
if(localName.equals("poster")) {
poster = true;
}
}
public void characters(char[] ch, int start, int len) {
str = new String(ch, start, len);
if(name) {
name = false;
}
if(detail) {
detail = false;
}
if(poster) {
tv.append("U R : " + str + "\n");
//tv.setText("fdfsdfsfsfdsfdsfsfsdfdsfdsdsfsdf");
//mPoster = str;
getPoster(str);
//mGrid.setAdapter(new ImageAdapter());
poster = false;
}
}
};
sp.parse(aurl, dHandler);
}
}