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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:25:23+00:00 2026-06-13T08:25:23+00:00

I am Android Newbie here I do not know how to pass the selected

  • 0

I am Android Newbie here I do not know how to pass the selected spinner text to pass to SMS as SMS text to send to selected number by pressing a button. I am happy if someone can teach me here.

public class MainActivity extends Activity { //all starts here
    String[] location;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        location = getResources().getStringArray(R.array.location_array);
        Spinner s1 = (Spinner) findViewById(R.id.spinner1);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, location);
        s1.setAdapter(adapter);
        s1.setOnItemSelectedListener(new OnItemSelectedListener()
        {
            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
            {
                int index = arg0.getSelectedItemPosition();
                Toast.makeText(getBaseContext(), "You have selected " + location[index], Toast.LENGTH_SHORT).show();

            }

            public void onNothingSelected(AdapterView<?> arg0){}

        });
    }

        public void onClick(View v) {          //<--**HERE IS THE PROBLEM**
        sendSMS("5556", "+location [index]"); //<--**HERE IS THE PROBLEM**
    }



    //?sends an SMS message to another device?
    private void sendSMS(String phoneNumber, String message)
    {
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, null, null);
    }

}

//-must end here

  • 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-13T08:25:23+00:00Added an answer on June 13, 2026 at 8:25 am

    First Save Selected value in one String Variable and then Send into SMS and another option is declare int index variable outside onItemSelected() function, sorry for my bad english communication but it will solve your problem, please see below link for more information.

    Spinners in Android

    and Use below code instead of your code.

    public class MainActivity extends Activity { //all starts here
        String[] location;
        int index;
        String mSelectedItem;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            location = getResources().getStringArray(R.array.location_array);
            Spinner s1 = (Spinner) findViewById(R.id.spinner1);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, location);
            s1.setAdapter(adapter);
            s1.setOnItemSelectedListener(new OnItemSelectedListener()
            {
                public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
                {
                    index = arg0.getSelectedItemPosition();
                    //OR you can also store selected item using below line.
                    mSelectedItem=arg0.getSelectedItem().toString();
                    Toast.makeText(getBaseContext(), "You have selected " + location[index], Toast.LENGTH_SHORT).show();
                }
    
                public void onNothingSelected(AdapterView<?> arg0){
    
                }
    
            });
        }
    
        public void onClick(View v) {
            sendSMS("5556", location [index]);
            //OR you can also send sms using below code.
            sendSMS("5556", mSelectedItem);
        }    
    
        //?sends an SMS message to another device?
        private void sendSMS(String phoneNumber, String message)
        {
            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(phoneNumber, null, message, null, null);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Extreme Android developer newbie here...well, new to Android development, not development in general. I
I am newbie in android so i am not famalier to all errors here
Android newbie here. I'm using this tutorial to show some rows that I fetch
NEWBIE ALERT! Here's the situation. I've got an Android ListActivity class (AppWindow) that contains
Android newbie here and would like to create a basic app using the AndriodPlot
Android developer newbie here.... In iOS, you can choose from two main styles (before
I'm newbie to Android development. I'm having problem here and hope someone could help
I'm a newbie iOS developer, recently developed several Android apps, but I'm not familiar
Android newbie question here. I've got an app that I'm experimenting with that the
android newbie here. My first game involves a custom view, which is going 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.