2

assume in visual studio i have a method :

    [WebMethod]
    public List<PhongTro> GetAllLodgingHousesByAddress(string address)
    {
        return db.GetAllLodgingHousesByAddress(address);
    }

How to convert return data type to a ArrayList in android?

0

1 Answer 1

3

You can use this code template as follow:

public ArrayList<PhongTro> getPhongTros() {
        ArrayList<PhongTro> arrPhongTro = new ArrayList<PhongTro>();

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.debug = true;

        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);

            /** contains all arrPhongTro objects */
            SoapObject response = (SoapObject) envelope.getResponse();

            /** lists property count */
            final int intPropertyCount = response.getPropertyCount();

            /** loop */
            for (int i = 0; i < intPropertyCount; i++) {
                /** temp SoapObject */
                SoapObject responseChild = (SoapObject) response.getProperty(i);

                /** temp PhongTro object */
                PhongTro tempObj = new PhongTro();

                if (responseChild.hasProperty("att0")) {
                    tempObj.setAtt0(responseChild.getPropertyAsString("att0"));
                }
                if (responseChild.hasProperty("att1")) {
                    tempObj.setAtt1(responseChild.getPropertyAsString("att1"));
                }

                if (responseChild.hasProperty("att2")) {
                    tempObj.setAtt2(responseChild.getPropertyAsString("att2"));
                }

                if (responseChild.hasProperty("att3")) {
                    tempObj.setAtt3(responseChild.getPropertyAsString("att3"));
                }

                if (responseChild.hasProperty("att4")) {
                    tempObj.setAtt4(responseChild.getPropertyAsString("att4"));
                }

                /** Adding temp PhongTro object to list */
                arrPhongTro.add(tempObj);
            }

        } catch (Exception e) {
            e.printStackTrace();

            /** if an error handled arrPhongTro setting null */
            arrPhongTro = null;
        }

        /** returning list */
        return arrPhongTro;
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks JPriest!i did it before u post but one more time i say thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.