Thursday, 8 August 2013

Parse XML using SAXParser and Thread. Looper Issue

Parse XML using SAXParser and Thread. Looper Issue

@Override
public void run(){
Looper.prepare();
final ProgressDialog p = new ProgressDialog(ChooserScreen.this);
p.setMessage("Loading Shows");
h.post(new Runnable(){
@Override
public void run() {
p.show();
}
});
try{
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
InputStream stream = new
URL("http://192.168.0.101:8080/xml/show.xml").openStream();
Reader r = new InputStreamReader(stream,"UTF-8");
InputSource source = new InputSource(stream);
source.setEncoding("UTF-8");
parser.parse(source, this);
}catch(Exception e){
e.printStackTrace();
}finally{
h.post(new Runnable(){
@Override
public void run() {
p.dismiss();
ExpandableListView chooserList = (ExpandableListView)
findViewById(R.id.chooserList);
MyAdapter adapter = new MyAdapter(ChooserScreen.this,
children);
chooserList.setAdapter(adapter);
}
});
Looper.myLooper().quit();
}
}
This is the code I am using to fetch XML from my local computer using my
phone. Both my phone and my computer are on the same network. However,
there are two issues:

XML file is not returned in reply. Although,
http://localhost:8080/xml/show.xml does. I am using Apache TomCat 7
I am not sure if the way I am using Looper in a Thread class is proper
Please help me sort this out

No comments:

Post a Comment