Skip to content Skip to sidebar Skip to footer

In Android This Program Not Retrieve The Xml Data After The Progress Bar Loading Help Me

\In android programming..i like to retrieve data's in the xmltags from url(xmlparsing) in the meantime i want to load progress until the data retrieve from xmltags. i attach my cod

Solution 1:

The Following code is Wrong.

U dont have any data in your onPostExecute() so whatever youe want to display just show that thing in onPostExecute() instead of doInBackground().

So change it ..

A sample example u can find in LazyLoading Or Asynctask App:-

https://github.com/thest1/LazyList

https://github.com/ethervoid/android-async-task-example

May with following code u can get ur ans...!!!!

Solution 2:

First u cannot make the UI related actions in the doInBackground()

If u want u can do it in the onPostExecute() after completed the doInBackground() process ...

So change ur logic ..

Solution 3:

NodeList namelist;
String[] no,na,c;
 try {
              URLurl=newURL("http://api.androidhive.info/pizza/?format=xml");          
              DocumentBuilderFactorydbf= DocumentBuilderFactory.newInstance();          
              DocumentBuilderdb= dbf.newDocumentBuilder();
              Documentdoc= db.parse(newInputSource(url.openStream()));
              doc.getDocumentElement().normalize();
              NodeListnodeList= doc.getElementsByTagName("item");

              no = newString[nodeList.getLength()];
              na = newString[nodeList.getLength()];
              c = newString[nodeList.getLength()];
              for (inti=0; i < nodeList.getLength(); i++) {
                  Nodenode= nodeList.item(i);

                  ElementfstElmnt= (Element) node;

                  NodeListidlist= fstElmnt.getElementsByTagName("id");
                  Elementnumelement= (Element) idlist.item(0);
                  idlist = numelement.getChildNodes();
                  no[i]=((Node) idlist.item(0)).getNodeValue();                     

                  NodeListnamelist= fstElmnt.getElementsByTagName("name");
                  Elementnamelement= (Element) namelist.item(0);
                  namelist = namelement.getChildNodes();
                  na[i]=((Node) namelist.item(0)).getNodeValue()

                  NodeListcostlist= fstElmnt.getElementsByTagName("cost");
                  Elementcostlement= (Element) costlist.item(0);
                  costlist = costlement.getChildNodes();


                  }} 
         catch (Exception e) {
                 }
    returnnull;

        }

        @OverrideprotectedvoidonPostExecute(String result)
{
    super.onPostExecute(result);
                LinearLayoutlayout=newLinearLayout(act.this);
                layout.setOrientation(1);
                TextView no[];
                TextView na[];
                TextView c[];
              no = newTextView[nodeList.getLength()];
              na = newTextView[nodeList.getLength()];
              c = newTextView[nodeList.getLength()];
              for (inti=0; i < nodeList.getLength(); i++) {

                  no[i] = newTextView(act.this);
                  na[i] = newTextView(act.this);
                  c[i] = newTextView(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(); 

        }

Post a Comment for "In Android This Program Not Retrieve The Xml Data After The Progress Bar Loading Help Me"