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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:21:02+00:00 2026-06-18T01:21:02+00:00

So I have set up part of my app where a user will select

  • 0

So I have set up part of my app where a user will select up to five things from from spinners (five spinners in total) and right now I have the button sending the selections to a new activity via an intent and they display on a new activity but I want to store the selections to an internal database on the button click and then the user can retrieve their selections from the menu buy pushing the button show data.

 public class IwiSelect extends Activity {

Spinner spinner1, spinner2, spinner3, spinner4, spinner5;
Button btnSubmit; 
String text;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_iwiselect);

    addListenerOnButton();
}
// get the selected drop down list value
  public void addListenerOnButton() {
    spinner1 = (Spinner) findViewById(R.id.spinner1);
    spinner2 = (Spinner) findViewById(R.id.spinner2);
    spinner3 = (Spinner) findViewById(R.id.spinner3);
    spinner4 = (Spinner) findViewById(R.id.spinner4);
    spinner5 = (Spinner) findViewById(R.id.spinner5);

    btnSubmit = (Button) findViewById(R.id.btnSubmit);

    btnSubmit.setOnClickListener(new OnClickListener() {

        public void onClick(View view) {

            String text0 = spinner1.getSelectedItem().toString();
            String text1 = spinner2.getSelectedItem().toString();
            String text2 = spinner3.getSelectedItem().toString();
            String text3 = spinner4.getSelectedItem().toString();
            String text4 = spinner5.getSelectedItem().toString();

            //Starting a new Intent
            Intent intent = new Intent(IwiSelect.this, SecondScreenActivity.class);

            //Sending data to another Activity
            intent.putExtra("IWI0", text0);
            intent.putExtra("IWI1", text1);
            intent.putExtra("IWI2", text2);
            intent.putExtra("IWI3", text3);
            intent.putExtra("IWI4", text4);


        // starting new activity
            startActivity(intent);

}
    });

  }
  }

this class sends the data to the new screen.

the class below is my helper class

 public class DatabaseHandler extends SQLiteOpenHelper {

    // All Static variables
    // Database Version
    private static final int DATABASE_VERSION = 1;

    // Database Name
    private static final String DATABASE_NAME = "iwi";

    //  table name
    private static final String TABLE_IWI = "iwis";


    //  Table Columns names
    private static final String KEY_ID = "id";
    private static final String KEY_NAME = "iwiname";


    public DatabaseHandler(SecondScreenActivity secondScreenActivity) {
        super((Context) secondScreenActivity, DATABASE_NAME, null, DATABASE_VERSION);
    }

     // Creating Tables
        @Override
       public void onCreate(SQLiteDatabase db) {
        String CREATE_IWI_TABLE = "CREATE TABLE " + TABLE_IWI + "("
                + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
                + " TEXT" + ")";
        db.execSQL(CREATE_IWI_TABLE);
    }

    // Upgrading database
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Drop older table if existed
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_IWI);

        // Create tables again
        onCreate(db);
    }




    // Deleting single contact
    public void deleteIwi(Iwi iwi) {}


    // Adding new contact
    public void addIwi(Iwi iwi) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, iwi.getName());


    // Inserting Row
    db.insert(TABLE_IWI, null, values);
    db.close(); // Closing database connection
    }

    // Getting single contact
    public Iwi getIwi(int id) {
     SQLiteDatabase db = this.getReadableDatabase();

     Cursor cursor = db.query(TABLE_IWI, new String[] { KEY_ID,
         KEY_NAME, }, KEY_ID + "=?",
         new String[] { String.valueOf(id) }, null, null, null, null);
     if (cursor != null)
     cursor.moveToFirst();

     Iwi iwi = new Iwi(Integer.parseInt(cursor.getString(0)),
          cursor.getString(1));
     // return contact
     return iwi;
     }


     // Getting All Contacts
       public List<Iwi> getAllIwi() {
     List<Iwi> iwiList = new ArrayList<Iwi>();
     // Select All Query
     String selectQuery = "SELECT  * FROM " + TABLE_IWI;

     SQLiteDatabase db = this.getReadableDatabase();
     Cursor cursor = db.rawQuery(selectQuery, null);

     // looping through all rows and adding to list
     if (cursor.moveToFirst()) {
      do {
         Iwi iwi = new Iwi();
         iwi.setID(Integer.parseInt(cursor.getString(0)));
         iwi.setName(cursor.getString(1));

         // Adding contact to list
         iwiList.add(iwi);
     } while (cursor.moveToNext());
     }

     // return contact list
     return iwiList;
    }

    //Getting contacts Count
    public int getIwiCount() {
    String countQuery = "SELECT  * FROM " + TABLE_IWI;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(countQuery, null);
    cursor.close();

    // return count
    return cursor.getCount();
    }

     // Updating single contact
    public int updateIwi(Iwi iwi) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, iwi.getName());


    // updating row
    return db.update(TABLE_IWI, values, KEY_ID + " = ?",
           new String[] { String.valueOf(iwi.getID()) });
   }

    // Deleting single contact
    public void deleteContact(Iwi iwi) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(TABLE_IWI, KEY_ID + " = ?",
           new String[] { String.valueOf(iwi.getID()) });
    db.close();
    }

    }
  • 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-18T01:21:03+00:00Added an answer on June 18, 2026 at 1:21 am

    If you want to store these values ; Instead of database , SharedPreferences can be used-

        SharedPreferences prefs = getApplicationContext().getSharedPreferences(
                  "com.example.app", Context.MODE_PRIVATE);
        // To Edit the shared preferences-
        SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
    
         editor.putString("IWI0", text0);
         editor.putString("IWI1", text1);
         editor.putString("IWI2", text2);
         editor.putString("IWI3", text3);
         editor.putString("IWI4", text4);
         editor.commit();
    
         // To retrieve the data--
         SharedPreferences prefs = getPreferences(MODE_PRIVATE); 
         String restoredText = prefs.getString("IWI0", null);
         if (restoredText != null) 
         {
           // Do something
         }
    

    Edit :
    Reference-
    http://developer.android.com/guide/topics/data/data-storage.html#pref

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

Sidebar

Related Questions

As part of our web application's build process, I have set up our XSLT
I have a set of three double values as part of an anonymous expression
I have set up an app that is registered for remote notifications. - (void)application:(UIApplication*)application
I have a java application that will run on Windows 7 (using Swing, App
A Ruby on Rails app will have access to a number of images and
I have written a user control that contains a text box and a button.
I have a set of connected web part on a page. Basically these are
Say that you have an iOS app, and a user that has one or
I have a rails app where the time zone is being set in application.rb:
I have two apps, which I will refer to as app A and app

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.