我得到了那个错误。我怎样才能消除 android.database.sqlite.SQLiteCursor@ 而不是单独的 INTEGER 值?我怎样才能从我的消费者表中获取整数值,即 AccountID 并将其作为 FOREiGN KEY 保存到我的消费表中?我的微调器处理程序
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
}
});
}
我的 SaveContact 到我的数据库
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());
}
}
我得到了这个错误!
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