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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:04:10+00:00 2026-06-05T05:04:10+00:00

I have a database and the database populates a listview. when i long press

  • 0

I have a database and the database populates a listview. when i long press a list item from the listview i get a context menu where i have the option to edit. When the edit option is clicked i open an activity and get all the values of the respective fields from the database. Now, here I want to get a value from the database and show it in the spinner. the spinner already has these values and is getting populated from the database… I have tried the following, but i get an error saying I can’t cast a SimpleCursorAdapter to an ArrayAdapter..

        String osub = cursor.getString(Database.INDEX_SUBJECT);
        Cursor cs = mDBS.querySub(osub);
        String subs = cs.getString(DatabaseSub.INDEX_SSUBJECT);
        if(cs!=null){
            ArrayAdapter<String> myAdap = (ArrayAdapter<String>) subSpinner.getAdapter();   
                              //cast to an ArrayAdapter

            int spinnerPosition = myAdap.getPosition(subs);

            //set the default according to value
            subSpinner.setSelection(spinnerPosition);

Please tell me how to do this.. Thank you.. I am relatively new so please let me know if I am overlooking something.

Thanks..

EDIT

querySub method

public Cursor querySub(String sub) throws SQLException {
    Cursor cursor = mDatabase.query(true, DATABASE_TABLE, sAllColumns, "ssub like " + "'" + sub + "'", null, null, null, null, null);
    if (cursor.moveToNext()) {
        return cursor;
    }
    cursor.moveToFirst();
    return cursor;
}

Error Log

06-05 12:11:14.144: E/AndroidRuntime(775): FATAL EXCEPTION: main
06-05 12:11:14.144: E/AndroidRuntime(775): java.lang.RuntimeException: Unable to start activity    ComponentInfo{an.droid.kit/an.droid.kit.DetailsActivity}: java.lang.ClassCastException:    android.widget.SimpleCursorAdapter cannot be cast to android.widget.ArrayAdapter
06-05 12:11:14.144: E/AndroidRuntime(775):  at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-05 12:11:14.144: E/AndroidRuntime(775):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-05 12:11:14.144: E/AndroidRuntime(775):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-05 12:11:14.144: E/AndroidRuntime(775):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-05 12:11:14.144: E/AndroidRuntime(775):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-05 12:11:14.144: E/AndroidRuntime(775):  at android.os.Looper.loop(Looper.java:137)
06-05 12:11:14.144: E/AndroidRuntime(775):  at android.app.ActivityThread.main(ActivityThread.java:4424)
06-05 12:11:14.144: E/AndroidRuntime(775):  at java.lang.reflect.Method.invokeNative(Native Method)
06-05 12:11:14.144: E/AndroidRuntime(775):  at java.lang.reflect.Method.invoke(Method.java:511)
06-05 12:11:14.144: E/AndroidRuntime(775):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-05 12:11:14.144: E/AndroidRuntime(775):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-05 12:11:14.144: E/AndroidRuntime(775):  at dalvik.system.NativeStart.main(Native Method)
06-05 12:11:14.144: E/AndroidRuntime(775): Caused by: java.lang.ClassCastException:     android.widget.SimpleCursorAdapter cannot be cast to android.widget.ArrayAdapter
06-05 12:11:14.144: E/AndroidRuntime(775):  at an.droid.kit.DetailsActivity.dbToUI(DetailsActivity.java:217)
06-05 12:11:14.144: E/AndroidRuntime(775):  at an.droid.kit.DetailsActivity.onCreate(DetailsActivity.java:104)
06-05 12:11:14.144: E/AndroidRuntime(775):  at android.app.Activity.performCreate(Activity.java:4465)
06-05 12:11:14.144: E/AndroidRuntime(775):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-05 12:11:14.144: E/AndroidRuntime(775):  at     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-05 12:11:14.144: E/AndroidRuntime(775):  ... 11 more
  • 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-05T05:04:11+00:00Added an answer on June 5, 2026 at 5:04 am

    I too encountered a similar problem. The issue: I had to set the spinner to a particular string value without knowing what position that string value was in the spinner control itself. The work around that I created was to take the spinner control and cycle through its text values. At each position compare the spinners text value to the given string value that I wanted to set it to. If it matches then get that current position and set my spinners selection based on that position.

    int spinnerPosition = 0;
    
    for (int i = 0; i < yourSpinner.getCount(); i++) 
    {
         Cursor cur = (Cursor)(yourSpinner.getItemAtPosition(i));
    
         //--When your bind you data to the spinner to begin with, whatever columns you
         //--used you will need to reference it in the cursors getString() method...
    
         //--Since "getString()" returns the value of the requested column as a String-- 
         //--(In my case) the 4th column of my spinner contained all of my text values 
         //--hence why I set the index of "getString()" method to "getString(3)"
    
         String currentSpinnerString = cur.getString(3).toString();
         if(currentSpinnerString.contains("place string you want to set the spinner to here"))
         {
            //--get the spinner position--
            spinnerPosition = i;
            break;
          }
     }
    
     yourSpinner.setSelection(spinnerPosition);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a dropdownlist that populates from the sql server database. populating the list
I have a listview which populates its content from SQLite Database. Here's my code:
I have a class with like 20 fields which get populated from SQL database
I have a list view which is populated via records from the database. Now
I have the following code, which basically takes values from a database and populates
I have a ListView with custom adapter which is populated from local sqlite database.
I have a list of images that are pulled from a database and loaded
I have a ListView in my activity that is populated from a database Cursor
I have a ListActivity with a ListView populated onStart with data from a database.
I have a listview which loads its data from sqlite database. Each row in

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.