Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8982859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:41:06+00:00 2026-06-15T20:41:06+00:00

HI im trying to pass array of items returned from aspx webservice to spinner

  • 0

HI im trying to pass array of items returned from aspx webservice to spinner in android. But it returns null. i would like to know what im doing wrong. I did try to return a set of strings before and it worked for the same connection, any help would be greatly appreciated.

My android code is as follows:

package com.example.fp1_webservicedropdown;

import android.R.string;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

import org.ksoap2.*;

import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.*;

public class MainActivity extends Activity {
    TextView result;
    Spinner spinnerC;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        spinnerC=(Spinner) findViewById(R.id.spinner1);
        result = (TextView) findViewById(R.id.textView2);

        final String NAMESPACE = "http://sample.com/";
        final String METHOD_NAME = "GetCustomerList";
        final String SOAP_ACTION = "http://sample.com/GetCustomerList";
        final String URL = "http://mylocalip/HelloWorldNew/Service1.asmx";

        SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
        //Request.addProperty("a", "32");
        //Request.addProperty("b", "12");
        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        soapEnvelope.dotNet = true;
        soapEnvelope.setOutputSoapObject(Request);
        AndroidHttpTransport aht = new AndroidHttpTransport(URL);

        try {
            aht.call(SOAP_ACTION, soapEnvelope);
            SoapPrimitive resultString = (SoapPrimitive) soapEnvelope
                    .getResponse();

            result.setText("The web service returned "
                    + resultString.toString());

            //---------- result To Spinner Code -----------------------//

            String[] toSpinner = new String[]{resultString.toString()};
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_spinner_item,  toSpinner );
                adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                spinnerC.setAdapter(adapter);

              //---------- result To Spinner Code ends here -----------------------//       
        } catch (Exception e) {

            e.printStackTrace();

        }
    }
}

and my web service code is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Collections;

namespace HelloWorldNew
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
     [WebService(Namespace = "http://sample.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {


        [WebMethod]
        public ArrayList GetCustomerList()
        {
            ArrayList list = new ArrayList();
            list.Add("Shean");
            list.Add("Yo");
            return list;
        }




    }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:41:07+00:00Added an answer on June 15, 2026 at 8:41 pm

    SoapPrimitive class definition:

    A class that is used to encapsulate primitive types (represented by a string in XML serialization). Basically, the SoapPrimitive class encapsulates “unknown” primitive types (similar to SoapObject encapsulating unknown complex types). For example, new SoapPrimitive (classMap.xsd, “float”, “12.3”) …

    You are returning an ArrayList and it’s not a Primitive type.

    Instead of SoapPrimitive , try using SoapObject.

    SoapObject response = (SoapObject) soapEnvelope.getResponse();
    

    Then use response.getProperyCount() to get number of items.

     int intPropertyCount = response.getPropertyCount();
    

    Then after casting each Property to SoapObject again, use toString() method. Like following:

    for (int i = 0; i < intPropertyCount; i++) {
        SoapObject responseChild = (SoapObject) response.getProperty(i);
        result.setText(responseChild.toString());
        // You can add all strings in a list and give ArrayAdapter<String> for Spinner
    }
    

    I hope this solves your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pass a value from an android spinner selection into a url.
I'm trying to pass an array like this using jQuery, but the PHP script
I am trying to pass array parameter to SQL commnd in C# like below,
I'm trying to pass an array in an ajax request, but apparently it doesn't
1.I was trying to pass an array of string from 1 activity to another
I'm trying to pass a byte array from inside my rails app into another
I'm trying to pass an array from view A to segue B, here's the
I am trying to pass a array that contains keys and values. The keys
I'm trying to pass an array to my template with a simple tag. I
I am trying to pass an array (2d) to a function as an parameter.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.