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 8800801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:41:08+00:00 2026-06-14T00:41:08+00:00

Here is my code to bind data in spinner with key(ProductName) and value(ProductID). But

  • 0

Here is my code to bind data in spinner with key(ProductName) and value(ProductID). But I am unable to get the value OnItemSelect.

public class BindDropDown {

    private String name;
    private String id;

    public String getName() {
        return name;
    }

    public void setNames(String name) {
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String toString() {
        return (name);
    }

}

and my android code:

public class SageActivity extends Activity implements OnItemSelectedListener {

    public final String SOAP_ACTION = "http://tempuri.org/PageLoadEvent ";
    public final String OPERATION_NAME = "PageLoadEvent ";
    public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
    public final String SOAP_ADDRESS = "http://192.168.7.106:90/MyWebserviceProfile/Service1.asmx";

    private static final String Cuspr_CustomerProductID = "Cuspr_CustomerProductID";
    private static final String ProdName = "ProdName";

    private EditText text1;

    private Button button;
    private Spinner spinnerProduct;

    Object item = null;
    JSONObject jsonObj = null;

    // you can use this array to find the school ID based on name
    ArrayList<BindDropDown> productList = new ArrayList<BindDropDown>();
    // you can use this array to populate your spinner
    ArrayList<String> productNames = new ArrayList<String>();
    ArrayAdapter<BindDropDown> spinnerArrayAdapter = null;
    // contacts JSONArray
    JSONArray custProduct = null;
    BindDropDown cp = new BindDropDown();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sage);
        text1 = (EditText) findViewById(R.id.editText1);
        spinnerProduct = (Spinner) findViewById(R.id.my_spinner);


        spinnerProduct.setOnItemSelectedListener(this);
        ConnectWS();

        Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                text1 = (EditText) findViewById(R.id.editText1);
                String txtID1 = spinnerProduct.getItemAtPosition(
                        spinnerProduct.getSelectedItemPosition()).toString();


            }
        });
    }

    public void ConnectWS() {

        SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
                OPERATION_NAME);
        PropertyInfo pi = new PropertyInfo();
        pi.setName("description");
        pi.setValue(text1.getText().toString());
        pi.setType(String.class);
        request.addProperty(pi);

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

        HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
        httpTransport.debug = true;
        String ss = httpTransport.responseDump;
        // Log.d("Result --- ", ss);

        Object response = null;
        SoapPrimitive result = null;

        try {
            httpTransport.call(SOAP_ACTION, envelope);

            if (envelope.bodyIn instanceof SoapFault) {
                String str = ((SoapFault) envelope.bodyIn).faultstring;
                Log.i("", str);
            } else {
                SoapObject so = (SoapObject) envelope.bodyIn;
                Log.d("WS", String.valueOf(so));

            }
            if (envelope.getResponse() != null) {
                result = (SoapPrimitive) envelope.getResponse();

                String json = result.toString();

                jsonObj = (JSONObject) new JSONTokener(json).nextValue();
                custProduct = jsonObj.getJSONArray("CustomerProduct");

                for (int i = 0; i < custProduct.length(); i++) {
                    JSONObject jsonObject = custProduct.getJSONObject(i);

                    cp.setNames(jsonObject.optString("ProdName"));
                    cp.setId(jsonObject.getString(Cuspr_CustomerProductID));
                    productList.add(cp);
                    productNames.add(jsonObject.optString("ProdName"));
                }
                spinnerProduct.setAdapter(new ArrayAdapter<String>(this,
                        android.R.layout.simple_spinner_dropdown_item,
                        productNames));

            } else { // uh oh response is null
            }

            // SoapPrimitive response = (SoapPrimitive) envelope.getResponse();

        } catch (Exception exception) {
            response = exception.toString();
        }
    }

    public void onNothingSelected(AdapterView<?> parent) {

    }

    public void onItemSelected(AdapterView<?> parent, View v, int position,
            long id) {

        Object test123 = spinnerProduct.getAdapter().getItem(position);
        // selection.setText(items[position]);
        // String test123 = jsonObject.getString(Cuspr_CustomerProductID);
        String txtID = cp.getId();
        text2.setText(txtID);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.sage, menu);
        return true;
    }

}

Any workaround I need to do get the values from the spinner..?

Regards
Raja M

  • 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-14T00:41:10+00:00Added an answer on June 14, 2026 at 12:41 am

    as you have productList, as Global variable to the Activity class, you can always access this list, so in onItemSelected get item of this list, and get id, and name from this item, as follows:

    public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
        BindDropDown item= productList.get(position);
        String txtID = item.getId();
        text2.setText(txtID);
    }
    

    Edit:

    Change loop in parsing to following:

    for (int i = 0; i < custProduct.length(); i++) {
                        JSONObject jsonObject = custProduct.getJSONObject(i);
                        BindDropDown cp=new BindDropDown();
                        cp.setNames(jsonObject.optString("ProdName"));
                        cp.setId(jsonObject.getString(Cuspr_CustomerProductID));
                        productList.add(cp);
                        productNames.add(jsonObject.optString("ProdName"));
                    }
    

    as the same object is being added to list repetatively.

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

Sidebar

Related Questions

how to assign value directly to kendo data-bind here is the code <script type=text/x-kendo-template
i bind linq result data to datagrid but nothing comes. here is my code
Here's some code, k.Bind<IGame>().To<Game>().Named(A) .WithConstructorArgument(ColorChoiceCount, 12); iGame = k.Get<IGame>(A); ((Game)iGame).SelectedColor = new GameColor(System.Drawing.Color.Red); iGame
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),
I am trying bind data from database into rich textbox here is my code:
For some reason my bind events won't work. You can see my code here:
Here is my code Socket sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); sck.Bind(new IPEndPoint(IPAddress.Any, 0));
I have a code that doesn't work. This is here http://jsfiddle.net/JPBarbosa/uxwTM/4/ . The data
i try to bind data to model with Html.EditorFor() helper and submit, but model
I write the following code to bind the data from a background object to

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.