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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:16:08+00:00 2026-06-11T02:16:08+00:00

I keep going round in circles with this one. I have managed to set

  • 0

I keep going round in circles with this one. I have managed to set the spinner to show item in the list if it matches a record in the database, but now have an issue with getting the selected item from the spinner when I save the record. I instead get something like ‘android.database.sqlite.SQLiteCursor@44fa41b0’.

In my saveInspection() method, I am using inspectedBySpinner.getSelectedItem().toString(); (as detailed in second answer in this post How do you get the selected value of a Spinner?) with no success.. (so close yet no banana!).

I’m sure this is something flippin obvious, but help much appreciated:

public class InspectionEdit extends Activity {

final Context context = this;

private EditText inspectionReferenceEditText;
private EditText inspectionCompanyEditText;
private Button inspectionDateButton;
private Spinner inspectedBySpinner;
private Button saveButton;
private Button cancelButton;
protected boolean changesMade;
private AlertDialog unsavedChangesDialog;
private Button addInspectorButton;

private int mYear;
private int mMonth;
private int mDay;
private StringBuilder mToday;
private RMDbAdapter rmDbHelper;
private long inspectionId;

private String inspectedBySpinnerData;

//private String inspectors;

static final int DATE_DIALOG_ID = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    rmDbHelper = new RMDbAdapter(this);
    rmDbHelper.open();
    Intent i = getIntent();
    inspectionId = i.getLongExtra("Intent_InspectionID", -1);
    setContentView(R.layout.edit_inspection);
    setUpViews();
    populateFields();
    fillSpinner();
    setTextChangedListeners();

}

private void setUpViews() {
    inspectionReferenceEditText =(EditText)findViewById(R.id.inspection_reference);
    inspectionCompanyEditText =(EditText)findViewById(R.id.inspection_company);
    inspectionDateButton =(Button)findViewById(R.id.inspection_date);
    inspectedBySpinner =(Spinner)findViewById(R.id.inspected_by_spinner);

    addInspectorButton = (Button)findViewById(R.id.add_inspector_button);
    saveButton = (Button)findViewById(R.id.inspection_save_button);
    cancelButton = (Button)findViewById(R.id.inspection_cancel_button);
}

 private void populateFields() {
        if (inspectionId > 0) {
            Cursor inspectionCursor = rmDbHelper.fetchInspection(inspectionId);
            startManagingCursor(inspectionCursor);
            inspectionReferenceEditText.setText(inspectionCursor.getString(
                    inspectionCursor.getColumnIndexOrThrow(RMDbAdapter.INSPECTION_REF)));
            inspectionCompanyEditText.setText(inspectionCursor.getString(
                    inspectionCursor.getColumnIndexOrThrow(RMDbAdapter.INSPECTION_COMPANY)));
            inspectionDateButton.setText(inspectionCursor.getString(
                    inspectionCursor.getColumnIndexOrThrow(RMDbAdapter.INSPECTION_DATE)));
            inspectedBySpinnerData = inspectionCursor.getString(
                    inspectionCursor.getColumnIndexOrThrow(RMDbAdapter.INSPECTION_BY));

            Toast.makeText(getApplicationContext(), inspectedBySpinnerData, 
                 Toast.LENGTH_LONG).show();
        }
    }

private void fillSpinner() {

    Cursor inspectorCursor = rmDbHelper.fetchAllInspectors();
    startManagingCursor(inspectorCursor);

    // create an array to specify which fields we want to display
    String[] from = new String[]{RMDbAdapter.INSPECTOR_NAME};
    //INSPECTOR_NAME = "inspector_name"
    // create an array of the display item we want to bind our data to
    int[] to = new int[]{android.R.id.text1};
    // create simple cursor adapter
    SimpleCursorAdapter spinnerAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, inspectorCursor, from, to );
    spinnerAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
    // get reference to our spinner
    inspectedBySpinner.setAdapter(spinnerAdapter);
    if (inspectionId > 0) {

        int spinnerPosition = 0; 

        for (int i = 0; i < inspectedBySpinner.getCount(); i++)  
        { 
             Cursor cur = (Cursor)(inspectedBySpinner.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(1).toString(); 

             if(currentSpinnerString.equals(inspectedBySpinnerData.toString())) 
             { 
                //--get the spinner position-- 
                spinnerPosition = i; 
                break; 
              } 
         }       
         inspectedBySpinner.setSelection(spinnerPosition); 
    }

}


 private void addInspector() {
    // get prompts.xml view
    LayoutInflater li = LayoutInflater.from(context);
    View promptsView = li.inflate(R.layout.prompt_dialog, null);

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            context);

    // set prompts.xml to alertdialog builder
    alertDialogBuilder.setView(promptsView);

    final EditText userInput = (EditText) promptsView
            .findViewById(R.id.editTextDialogUserInput);

    // set dialog message
    alertDialogBuilder
        .setCancelable(false)
        .setPositiveButton("OK",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int id) {
            // get user input and set it to result
            // edit text
            String inspector = userInput.getText().toString();
            rmDbHelper.createInspector(inspector);

            }
          })
        .setNegativeButton("Cancel",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int id) {
            dialog.cancel();
            }
          });

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show();
 }

private void setTextChangedListeners() {
     changesMade = false;

     inspectionReferenceEditText.addTextChangedListener(new TextWatcher(){
         public void afterTextChanged(Editable s) {
         }
         public void beforeTextChanged(CharSequence s, int start, int count, int after) {
         }
         public void onTextChanged(CharSequence s, int start, int before, int count) {
             changesMade = true;
         }  
    });

     inspectionCompanyEditText.addTextChangedListener(new TextWatcher(){
        public void afterTextChanged(Editable s) {
        }
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            changesMade = true;
        }   
    }); 

     inspectionDateButton.addTextChangedListener(new TextWatcher(){
        public void afterTextChanged(Editable s) {
        }
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            changesMade = true;
        }   
    });

    inspectionDateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showDialog(DATE_DIALOG_ID);
        }
    });

    addInspectorButton.setOnClickListener(new View.OnClickListener() {                      
        public void onClick(View v) {
            addInspector();
        }
    });

    saveButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            saveInspection();
            finish();
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        cancel();
        }
    });
  }

protected void saveInspection() {
    String reference = inspectionReferenceEditText.getText().toString();
    String companyName = inspectionCompanyEditText.getText().toString();
    String inspectionDate = RMUtilities.compareTwoStringsNullIfSame(inspectionDateButton.getText().toString(), "Click to add");
    String inspectedBy = inspectedBySpinner.getSelectedItem().toString();
    Toast.makeText(getApplicationContext(), inspectedBy, 
            Toast.LENGTH_LONG).show();
    if (inspectionId > 0) {
        rmDbHelper.updateInspection(inspectionId, reference, companyName, inspectionDate, inspectedBy);
        Toast.makeText(getApplicationContext(), "Inspection updated", 
                Toast.LENGTH_LONG).show();
    }
    else {
        rmDbHelper.createInspection(reference, companyName, inspectionDate, inspectedBy);
        Toast.makeText(getApplicationContext(), "Inspection created", 
                Toast.LENGTH_LONG).show();
    }

}
  • 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-11T02:16:10+00:00Added an answer on June 11, 2026 at 2:16 am

    As you use a CursorAdapter and not an Adapter based on a List or Array of String, you’ll have to use the Cursor to fetch the value of the selected item. The Spinner’s getSelectedItem will call the CursorAdapter’s getItem(position) which will return the Cursor object. So instead to using toString(), first cast the returned object to a Cursor and then use Cursor’s get... methods to fetch the required data of the selected item.

    EDIT

    Based on how you fill your spinner you’ll probably need this:

    String inspectedBy = ((Cursor)inspectedBySpinner.getSelectedItem())
                            .getString(1).toString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Keep going around circles, but I am still unclear about this. Have a feeling
I should be able to figure this out, but I keep going in circles.
I've been going round in circles with what must be a very simple challenge
We have an application whose virtual memory rises and keep going for over a
I have a timer for my game, but the message will keep going on
How can I keep going through .next() s until I find the one with
I got a string, that inside it has: 2@0.88315@1@1.5005@true@0.112 and it keep going... I
Lets say we have this code: bool KeepGoing = true; DataInThread = new Thread(new
Keep running into When using the multi-mapping APIs ensure you set the splitOn param
(Keep in mind this is on OSX Snow Leopard) I don't know how to

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.