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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:32:12+00:00 2026-06-03T01:32:12+00:00

I want the selected value from a spinnner to be kept in memory or

  • 0

I want the selected value from a spinnner to be kept in memory or temp table or anywhere, so that it can be used on next tab.
I watched lot of tutorials, but didn’t find any solution.
I’ve the following code (it gives me toast message only; I populate the spinner from a database):

super.onCreate(savedInstanceState);
    setContentView(R.layout.customers);
    addFromDB();
    select_cust_name=(EditText)findViewById(R.id.select_cust_name);
}

private void addFromDB() {
    // TODO Auto-generated method stub
    final Spinner spinner = (Spinner) findViewById(R.id.spinner_db);
    resultsView = (TextView) findViewById(R.id.textView);
    SQLiteDatabase myDB = null;
    myDB = this.openOrCreateDatabase(SAMPLE_DB_NAME, 1, null);
    // ////////////These are using to add the values to database
    myDB.execSQL("CREATE TABLE " + SAMPLE_TABLE_NAME + " (" + _id
            + " INTEGER PRIMARY KEY AUTOINCREMENT , " + cust_name
            + " TEXT , " + cust_add + " TEXT)");
    myDB.execSQL("insert into tbl_customer(cust_name, cust_add) values ('Fool', 'FF' );");

    final Cursor c = myDB.query(SAMPLE_TABLE_NAME, null, null, null, null, null, null);
    char _idColumnIndex = (char) c.getColumnIndexOrThrow("_id");
    char cust_nameColumnIndex = (char) c.getColumnIndexOrThrow("cust_name");
    char cust_addColumnIndex = (char) c.getColumnIndexOrThrow("cust_add");
    adapterForSpinner = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item);
    adapterForSpinner
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    spinner.setAdapter(adapterForSpinner);
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {


public void onItemSelected(AdapterView<?> parent, View view,
                    int pos, long id) {
                // TODO Auto-generated method stub

                SQLiteDatabase myDB = null;
                Toast.makeText(
                        parent.getContext(),
                        "Customer is "
                                + parent.getItemAtPosition(pos).toString(),
                        Toast.LENGTH_LONG).show();
             String selected = parent.getItemAtPosition(pos).toString();
        insert(selected);

Thanks in advance.

here is my log:

05-03 11:29:31.743: E/Cursor(10155): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/tab.layout/databases/db_sales, table = tbl_customer, query = SELECT * FROM tbl_customer
05-03 11:29:31.743: E/Cursor(10155): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
05-03 11:29:31.743: E/Cursor(10155):    at android.database.sqlite.SQLiteCursor.<init>(SQLiteCursor.java:210)
05-03 11:29:31.743: E/Cursor(10155):    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
05-03 11:29:31.743: E/Cursor(10155):    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
05-03 11:29:31.743: E/Cursor(10155):    at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
05-03 11:29:31.743: E/Cursor(10155):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
05-03 11:29:31.743: E/Cursor(10155):    at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1264)
05-03 11:29:31.743: E/Cursor(10155):    at tab.layout.Customers.addFromDB(Customers.java:63)
05-03 11:29:31.743: E/Cursor(10155):    at tab.layout.Customers.onCreate(Customers.java:40)
05-03 11:29:31.743: E/Cursor(10155):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-03 11:29:31.743: E/Cursor(10155):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-03 11:29:31.743: E/Cursor(10155):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
05-03 11:29:31.743: E/Cursor(10155):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
05-03 11:29:31.743: E/Cursor(10155):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
05-03 11:29:31.743: E/Cursor(10155):    at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
05-03 11:29:31.743: E/Cursor(10155):    at android.widget.TabHost.setCurrentTab(TabHost.java:323)
05-03 11:29:31.743: E/Cursor(10155):    at android.widget.TabHost.addTab(TabHost.java:213)
05-03 11:29:31.743: E/Cursor(10155):    at tab.layout.MyTablayoutActivity.SetupTabs(MyTablayoutActivity.java:48)
05-03 11:29:31.743: E/Cursor(10155):    at tab.layout.MyTablayoutActivity.onCreate(MyTablayoutActivity.java:20)
05-03 11:29:31.743: E/Cursor(10155):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-03 11:29:31.743: E/Cursor(10155):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-03 11:29:31.743: E/Cursor(10155):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-03 11:29:31.743: E/Cursor(10155):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-03 11:29:31.743: E/Cursor(10155):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-03 11:29:31.743: E/Cursor(10155):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 11:29:31.743: E/Cursor(10155):    at android.os.Looper.loop(Looper.java:123)
05-03 11:29:31.743: E/Cursor(10155):    at android.app.ActivityThread.main(ActivityThread.java:4627)
05-03 11:29:31.743: E/Cursor(10155):    at java.lang.reflect.Method.invokeNative(Native Method)
05-03 11:29:31.743: E/Cursor(10155):    at java.lang.reflect.Method.invoke(Method.java:521)
05-03 11:29:31.743: E/Cursor(10155):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 11:29:31.743: E/Cursor(10155):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 11:29:31.743: E/Cursor(10155):    at dalvik.system.NativeStart.main(Native Method)
  • 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-03T01:32:14+00:00Added an answer on June 3, 2026 at 1:32 am

    A couple options…

    Global Variable

    Declare it in your main activity

    public class Main extends Activity {
        public static String myString;  // declare global variable
    }
    

    Sett from anywhere…

    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
             Main.myString = parent.getItemAtPosition(pos).toString();
    }
    

    Then you can just use Main.myString in whatever your next activity/tab/fragment is.

    You didn’t say how you were doing the tabs (if they were a new activity or not) so another possible way is to pass it through an intent extra.

    Pass in intent

    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
        Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
        myIntent.putExtra("Selected", parent.getItemAtPosition(pos).toString());
        CurrentActivity.this.startActivity(myIntent);
    }
    

    then in the new activity retrieve it like so:

    Bundle extras = getIntent().getExtras();
    String selected = extras.getString("Selected");
    

    Hope this helps.

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

Sidebar

Related Questions

to get the selected value from HTML select: options[selectedIndex].value what if i want to
How can I get the selected value from DetailsView to a textbox? So far
I have a drop down list and I want the selected value to put
I have a dropdownlist.I want to add selected value of it to a hyperlink
I want to pass in the session scoped the selected radio button value. My
I want to make a judge, if checkbox value = 2, selected. But now
I want to use a dependency property so that my label displays values selected
Hi I want to delete selected item from the data base. My code is
i want to display selected value in drop down list . the value comes
I want to select a random value from a array, but keep it unique

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.