1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
public class MonActivite extends Activity {
/** Create Object For SiteList Class */
SitesList sitesList = null;
ListView lvListe;
List<Livre> maBibliotheque = new ArrayList<Livre>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
/** Handling XML */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Send URL to parse XML Tags */
URL sourceUrl = new URL(
"http://www.androidpeople.com/wp-content/uploads/2010/06/example.xml");
/** Create handler to handle XML Tags ( extends DefaultHandler ) */
MyXMLHandler myXMLHandler = new MyXMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
/** Get result from MyXMLHandler SitlesList Object */
sitesList = MyXMLHandler.sitesList;
lvListe = (ListView)findViewById(R.id.lvListe);
RemplirLaBibliotheque();
LivreAdapter adapter = new LivreAdapter(this, maBibliotheque);
lvListe.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
private void RemplirLaBibliotheque() {
for (int i = 0; i < sitesList.getName().size(); i++) {
maBibliotheque.clear();
maBibliotheque.add(new Livre("Name:"+ sitesList.getName().get(i), "William-C Dietz"));
}
}
} |
Partager