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

  • Home
  • SEARCH
  • 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 6184407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:31:52+00:00 2026-05-24T01:31:52+00:00

I am struggling with Android Lists and how to convert them for use in

  • 0

I am struggling with Android Lists and how to convert them for use in a Spinner. Putting a string array into a Spinner is very simple, therefore, I figured doing the same with a List would also be simple. At this time however I can not figure out how to get the List into the proper format for use with the Spinner’s ArrayAdapter.

Here’s my code for grabbing a list of account names from the database:

//---retrieves all the accounts matching the account_type---
    public List getAccounts(String account_type) {      
        List<String> list = new ArrayList<String>();
        Cursor cursor = this.db.query(DBACCOUNTS, new String[] {
                ID,
                ACCOUNTTYPE,
                ACCOUNTNUMBER,
                ACCOUNTNAME},
                ACCOUNTTYPE + " = " + "'" + account_type + "'",
                null, 
                null, 
                null, 
                null, 
                null);
        if (cursor.moveToFirst()) {
           do {
              //---account_name column number is 3--- 
              list.add(cursor.getString(3));
           } while (cursor.moveToNext());
        }
        if (cursor != null && !cursor.isClosed()) {
           cursor.close();
        }

        return list;
    }

From the returned “list”, what do I need to do to populate my spinner? The following code is obviously for a string array, however, I am lost as to what I need to do to make a List work with similar functionality. Here’s my non-working ArrayAdapter code (account_name_array is set to be the returned “list” from above):

account_name_spinner = (Spinner) findViewById(R.id.account_name_spinner);      
account_name_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, account_name_array);
account_name_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
account_name_spinner.setAdapter(account_name_adapter);

I know I am way off track here, I know that ArrayAdapter is expecting a string array, however, like I said, I need a good push in the right direction. Obviously I need to either convert my List into a string array, or change the way I am adapting the Spinner to the List. Android has been quite difficult for me to grasp, there are a lot of data structures and much more data type rules than I am use to coming from a PHP background.

You’re help is greatly appreciated!

  • 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-05-24T01:31:53+00:00Added an answer on May 24, 2026 at 1:31 am

    Use toArray to convert your list into an array.

    List<String> list = new ArrayList<String>(); // Your list
    // Populate it
    
    // Then get an array:
    String[] array = list.toArray( new String[0] );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to programming in Android, but have been struggling all day with
Using Java on Android I'm struggling to convert a couple of html special characters.
I am struggling with a warning in my android project when i use jsf-impl.jar
Been struggling with this simple selector problem a couple of hours now and must
im struggling with syntax here: hopefully this question is v simple, im just miising
I'm struggling with this Looper in Android. I have a timer that runs every
I have been struggling with a unit testing problem on Android for a while
I was struggling for past one week to do obfuscate with android application can
I am struggling a bit with the LocationListener in Android. I want to make
Just trying out a couple of Android samples. Struggling to find the method managedQuery

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.