title: How to get selected item in Spinner
body: <p>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'.  </p>
  
  <p>In my saveInspection() method, I am using inspectedBySpinner.getSelectedItem().toString(); (as detailed in second answer in this post <a href="https://stackoverflow.com/questions/2652414/how-do-you-get-the-selected-value-of-a-spinner-android">How do you get the selected value of a Spinner?</a>) with no success.. (so close yet no banana!).  </p>
  
  <p>I'm sure this is something flippin obvious, but help much appreciated:</p>
  
  <pre><code>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 &gt; 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 &gt; 0) {
  
          int spinnerPosition = 0; 
  
          for (int i = 0; i &lt; 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 &gt; 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();
      }
  
  }
  </code></pre>