Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>NodeList namelist; String[] no,na,c; try { URL url = new URL("http://api.androidhive.info/pizza/?format=xml"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(url.openStream())); doc.getDocumentElement().normalize(); NodeList nodeList = doc.getElementsByTagName("item"); no = new String[nodeList.getLength()]; na = new String[nodeList.getLength()]; c = new String[nodeList.getLength()]; for (int i = 0; i &lt; nodeList.getLength(); i++) { Node node = nodeList.item(i); Element fstElmnt = (Element) node; NodeList idlist = fstElmnt.getElementsByTagName("id"); Element numelement = (Element) idlist.item(0); idlist = numelement.getChildNodes(); no[i]=((Node) idlist.item(0)).getNodeValue(); NodeList namelist = fstElmnt.getElementsByTagName("name"); Element namelement = (Element) namelist.item(0); namelist = namelement.getChildNodes(); na[i]=((Node) namelist.item(0)).getNodeValue() NodeList costlist = fstElmnt.getElementsByTagName("cost"); Element costlement = (Element) costlist.item(0); costlist = costlement.getChildNodes(); }} catch (Exception e) { } return null; } @Override protected void onPostExecute(String result) { super.onPostExecute(result); LinearLayout layout = new LinearLayout(act.this); layout.setOrientation(1); TextView no[]; TextView na[]; TextView c[]; no = new TextView[nodeList.getLength()]; na = new TextView[nodeList.getLength()]; c = new TextView[nodeList.getLength()]; for (int i = 0; i &lt; nodeList.getLength(); i++) { no[i] = new TextView(act.this); na[i] = new TextView(act.this); c[i] = new TextView(act.this); no[i].setText("ID="+no[i] ); na[i].setText("pizza name="+ na[i]); c[i].setText("cost="+ ((Node) costlist.item(0)).getNodeValue()); layout.addView(no[i]); layout.addView(na[i]); layout.addView(c[i]); setContentView(layout); mDialog.dismiss(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload