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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:55:57+00:00 2026-05-25T22:55:57+00:00

I am using the CustomHttpClient to connect and do queries from my android app.

  • 0

I am using the CustomHttpClient to connect and do queries from my android app. I was wondering if it was possible to populate a spinner from a php/mysql query and if so how it would be done?

  • 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-25T22:55:58+00:00Added an answer on May 25, 2026 at 10:55 pm

    So this should actually be fairly easy. You haven’t really given us much to work on in terms of implementations details so I’ll do my best to semi-psuedo code things out for you and give you a good general answer.

    We’re going to want to do the query from a separate thread so as to not block the UI thread while we’re waiting for a network response. You can do this many different ways including using an AsyncTask, IntentService, or some sort of Loader. I’m thinking in your case a custom class derived form the AsyncTaskLoader class will be the best. So lets see how this would look (note you’ll need access to some of the newer apis in order to use the loader, checkout the http://developer.android.com/resources/articles/backward-compatibility.html if you’re writing this application for anything less than api level 11).

    MyActivity extends Activity implements LoaderManager.LoaderCallbacks<List<SpinnerItem>>{
      private Adapter<SpinnerItem> spinnerAdapter;
      private static final int SPINNER_LOADER_ID = 0;
    
      public void onCreate(Bundle icicle){
         Spinner theSpinner = findViewById(R.id.the_spinner);
         spinnerAdapater = new Adapter<SpinnerItem>(...); //create empty adapter
         spinnerAdapater.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
         theSpinner.setAdapter(spinnerAdapater);
         getLoaderManager().initLoader(SPINNER_LOADER_ID, null, this);
      }
    
      public Loader<List<SpinnerItems>> onCreateLoader(int id, Bundle arg){
        //Create and return your loader
      }
    
      public void onLoadFinish(Loader<List<SpinnerItem>> loader, List<SpinnerItem> data){
        //update your adapater with the new data
      }
    
      public void onLoaderReset(Loader<List<SpinnerItem>> loader){
        //clear out all the data in the adapter
      }
    
    }
    

    This is all pretty straight-forward stuff here. You should be able to fill in the gaps by reading about loaders, adapters, etc. on the Android dev pages. The fact that we’re using a “List” full of “SpinnerItem”s is of course going to be dependent on your particular implementation, as is the type of adapter you choose to use. Feel free to choose whatever actual data structures you want. Once again, consult the Android dev pages for details. As far as the loader class goes, you’ll wanna do something like this:

    MyNetworkLoader extends AsyncTaskLoader<List<SpinnerItem>>
      public MyNetworkLoader(Context context){
        super(context);
      }
    
      List<SpinnerItem> loadInBackground(){
         //Get data from server
      }
    }
    

    In the loadInBackground method you’ll use your CustomHttpClient to query your server and convert the response into some sort of data structure (just as before, in this example we’re using a “List” of “SpinnerItem”s).

    As a final note, your spinner is going to be empty until your network request completes. You may want to include some sort of logic informing the user that the contents of the spinner are loading.

    That’s it. The new loader api’s make things really simple.

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

Sidebar

Related Questions

Using php/html, I want to retrieve email addresses (plus other information) from MySQL and
Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter
The Andriod app I'm developing is using Http Gets/Posts using PHP files on my
Using the following query: SELECT sum(severity) as Score, DATE_FORMAT(LAST_UPDATE,%Y-%m) as score_date FROM missingpatches GROUP
Using import datetime in python, is it possible to take a formatted time/date string
Using Rails 3.2.0 with haml and sass: I Would like to link an external
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using android 2.3.3, I have a background Service which has a socket connection. There's
I'm newbie. Now i face this kind of question. I am using the CustomHttpClient
Using mercurial, I've run into an odd problem where a line from one committer

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.