How to generate a parse, to read an xml and show it in a listview with soap

1

Good afternoon

I'm in a development of an app that consumes webservices, the point is that he sends me a menu method that is an xml, I need to read it and show it as a menu in my app, I'm looking to show it in a listview, but not I know how to do the parse, they could help me explain ... now I have my connection to the webservices and it brings me the data, I was already doing it in another way but when the background method ends it does not happen to execute to fill my listview .. help me

webservices code, I have this code in a class called webservices (invoke)

 public static ArrayList Menu() {

        // Create request
        SoapObject request = new SoapObject("http://oncontrol.no-ip.net:9020/","Menu");
        // Property which holds input parameters

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.implicitTypes=false;
        // Set output SOAP object
        envelope.setOutputSoapObject(request);
        // Create HTTP call object
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,7000);

        ArrayList MenuArray = new ArrayList();
        //ArrayAdapter<String>  arrayadapter;
        try {
            androidHttpTransport.debug=true;
            // Invoke web service
            androidHttpTransport.call("http://oncontrol.no-ip.net:9020/Menu", envelope);
            String ss=androidHttpTransport.responseDump;
            // Get the response
            // SoapObject obj1 = (SoapObject) envelope.bodyIn;
            // SoapObject obj2 = (SoapObject) obj1.getProperty(0);
            SoapObject response = (SoapObject)envelope.getResponse();

            SoapObject obj1 = (SoapObject) envelope.getResponse();

            SoapObject obj2 =(SoapObject) obj1.getProperty(1);

            SoapObject obj3 =(SoapObject) obj2.getProperty(0);

            for(int i=0; i<obj3.getPropertyCount(); i++)
            {
                SoapObject obj4 =(SoapObject) obj3.getProperty(i);
                int id= Integer.parseInt(obj4.getProperty("Id").toString());
                String Descripcion = obj4.getProperty("Descripcion").toString();
                MenuArray.add(i,Descripcion);
            }

        } catch (Exception e) {
            //Assign Error Status true in static variable 'errored'
            //menu.errored = true;
            e.printStackTrace();
        }
        //Return booleam to calling object
        //return loginStatus;

        return MenuArray;
    }
}
    
asked by Hugo Rodriguez 22.04.2016 в 00:22
source

1 answer

1

This would be the Asynctask, the return of doInBackground() should not be null, and the onProgressUpdate() is not necessary:

private class AsyncCallWSMenu extends AsyncTask<String, ArrayList, ArrayList> {



        @Override
        protected ArrayList doInBackground(String... params)         {
            MenuArrayList=webService.Menu();

            return "";
        }

        @Override
        //Make Progress Bar visible
        protected void onPreExecute() {

            dialog=new ProgressDialog(menu.this);
            dialog.setIndeterminate(false);
            dialog.setMessage("Loding...");
            dialog.setCancelable(false);
            dialog.show();

        }

    /*   @Override
        protected void onProgressUpdate(ArrayList... values) {
            super.onProgressUpdate(values);
        }*/

        //Once WebService returns response
        @Override
        protected void onPostExecute(ArrayList arrayList) {
            if (!MenuArrayList.isEmpty()){
                arrayadapter = new ArrayAdapter<String>(menu.this,
                        android.R.layout.simple_list_item_activated_1, MenuArrayList);
                list.setAdapter(arrayadapter);
            }

            dialog.dismiss();
        }
    }
}
    
answered by 22.04.2016 / 16:42
source