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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:24:23+00:00 2026-06-01T12:24:23+00:00

I am populating several fields based on data from the my db. I am

  • 0

I am populating several fields based on data from the my db. I am having trouble figuring out how to use the data from the db to select an item that is in the spinner. The Spinner has four options and when entering data into the db I choose one. Now when I call the db I want to have that option show up as the one chosen in the spinner. Basically I am trying to get the option in the db to be the one showing in the spinner. The commented out line are what I have tried, but do not work. Any ideas?

 truckNumber = (Spinner) findViewById(R.id.truck_number);
    drivable = (RadioButton) findViewById(R.id.drivable);
    notDrivable = (RadioButton) findViewById(R.id.not_drivable);
    truck = (RadioButton) findViewById(R.id.truck);
    trailer = (RadioButton) findViewById(R.id.trailer);
    aa = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, trucks);
    bb = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, trailers);
    newTime = new Time();
    edit= new Inspection();
    long something = edit.returnID();
    updateDB= new InspectionDBAdapter(this);
    if(something>0)
    {
        updateDB.open();    
        Cursor result= updateDB.getOneInspection(something);
        result.moveToFirst();
        int odo=result.getColumnIndex("odometer");
        int firstDriver=result.getColumnIndex("driver");
        int secondDriver=result.getColumnIndex("codriver");
        int driveCondition=result.getColumnIndex("status");
        int vehicleType=result.getColumnIndex("vehicle_type");
        int truckNum=result.getColumnIndex("vehicle_id");
        driver.setText(result.getString(firstDriver));
        odometer.setText(result.getString(odo));
        coDriver.setText(result.getString(secondDriver));
    //  truckNumber.setAdapter(aa.getPosition(result.getString(truckNum).to));
    //  truckNumber.setSelection(result.getString(truckNum).toString());
        if(result.getString(driveCondition).equals("1"))
            drivable.setChecked(true);
        else
            notDrivable.setChecked(true);

        if(result.getString(vehicleType).equals("truck"))
            truck.setChecked(true);
        else
            trailer.setChecked(true);

        result.close();
        updateDB.close();
    }

update: Found the answer at How to set selected item of Spinner by value, not by position?. The second answer with 48 votes

  • 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-01T12:24:24+00:00Added an answer on June 1, 2026 at 12:24 pm

    I didn’t exactly understand your question, however

    truckNumber.setAdapter(aa.getPosition(result.getString(truckNum).toString));
    

    must not even compile. You probably wish to do

    truckNumber.setAdapter(aa);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data SELECT [field names] FROM [several joined tables] WHERE [some criteria
I am populating a SelectList w/ data that comes back from an AJAX call.
Im populating a GridView from List so am forced to use TemplateField controls to
I am populating a combobox dropdown with node fields from an Xml document. I
I am having an issue populating a data table with the correct data. I
I am pulling data from a database with Ajax and dynamically populating a div
I am populating my database from online data using the loop like (simplified, with
I am populating a set of arrays from worksheet data. I then manipulate the
I have a situation which involves several threads simultaneously populating a database with data
I have a data entry form that had several comboboxes on it. Each of

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.