I got that Error. How could I eliminate the android.database.sqlite.SQLiteCursor@ instead of INTEGER value alone? And how could I get the integer Value from my consumer table which is AccountID and Save it as FOREiGN KEY into my consumptions table? My Spinner Handler
private void loadSpinnerData() {
// database handler
SQLiteDatabase db = new DatabaseOpenHelper(this).getWritableDatabase();
spinner = (Spinner)findViewById(R.id.spinner);
// Spinner Drop down elements
// List<String> lables = db.getAllLabels();
Cursor c = db.rawQuery(
"SELECT AccountID AS _id, ConsumerName FROM Consumers", null);
startManagingCursor(c);
// Creating adapter for spinner
String[] from = new String[] { "_id"};
int[] to = new int[] { android.R.id.text1 };
SimpleCursorAdapter dataAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_spinner_item, c, from, to);
// Drop down layout style - list view with radio button
dataAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
// set spinner listener to display the selected item id
mContext = this;
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// On selecting a spinner item
//String label = parent.getItemAtPosition(position).toString();
Cursor c = (Cursor)parent.getItemAtPosition(position);
mSpinnerSpeciesId = c.getInt(c.getColumnIndexOrThrow("_id"));
Toast.makeText(mContext, "Selected ID=" + c,
Toast.LENGTH_LONG).show();
// Showing selected spinner item
/*
* Toast.makeText(parent.getContext(), "You selected: " + label,
* Toast.LENGTH_LONG).show();
*/
}
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
My SaveContact into my database
private void saveContact() {
DatabaseConnector dbConnector = new DatabaseConnector(this);
if (getIntent().getExtras() == null) {
dbConnector.insertConsumption(meterNoEt.getText().toString(),
currentEt.getText().toString(), previousEt.getText()
.toString(), kWhEt.getText().toString(), dateTv
.getText().toString(), spinner.getSelectedItem()
.toString()
);
} else {
dbConnector.updateConsumption(rowID,
currentEt.getText().toString(), previousEt.getText()
.toString(), kWhEt.getText().toString(), dateTv
.getText().toString(), spinner.getSelectedItem()
.toString());
}
}
And I Got this Error!
02-18 23:42:26.321: E/SQLiteDatabase(29864): Error inserting ConsumerName=android.database.sqlite.SQLiteCursor@4144bbe0 kWh=40300.0 _id=355477 Date=2013 -2-18 Previous=5587 Current=45887