I’m sure glad this site is here. It has helped me out every time.
So my new problem is, I have passed a value from one activity to another and set that value to a text view. The value is always numeric. I then use “on menu item selected” to pass that value to another activity and set that value to a text view. What I’m looking to do is use that value (which is numeric and represents the row id associated with the data) to query the database and return the row associated with the numeric value mentioned earlier. Then populate the appropriate edit text or text views of the same activity.
Here is where I call for the text value (tv1)
private void populateFields() {
if (tv1!=null) {
Cursor note = mDbHelper.fetchRow(tv1);
startManagingCursor(note);
//rowid.setText(note.getString(
// note.getColumnIndexOrThrow(DatabaseManager.KEY_ROWID)));
txtbox28.setText(note.getString(
note.getColumnIndexOrThrow(DatabaseManager.KEY_NAME)));
txtbox1.setText(note.getString(
note.getColumnIndexOrThrow(DatabaseManager.NICBASEML)));
txtbox4.setText(note.getString(
note.getColumnIndexOrThrow(DatabaseManager.NICDROPS)));
txtbox8.setText(note.getString(
note.getColumnIndexOrThrow(DatabaseManager.NICPERCT)));
and the query
public Cursor fetchRow(TextView tv1) throws SQLException {
Cursor mCursor =
mDb.query(true,DATABASE_TABLE, new String[] {KEY_ROWID, KEY_NAME,
NICBASEML, NICDROPS, NICPERCT, PGML, PGDROPS,PGPERCT,
VGML,VGDROPS,VGPERCT, WAPML, WAPDROPS, WAPPERCT,
FLV1NAME, FLV1ML, FLV1DROPS, FLV1PERCT,
FLV2NAME, FLV2ML, FLV2DROPS, FLV2PERCT,
FLV3NAME, FLV3ML, FLV3DROPS, FLV3PERCT,
FLV4NAME, FLV4ML, FLV4DROPS, FLV4PERCT,
DROPSML, AMOUNT, FINALNIC, BPG, BVG, BASENIC}, KEY_ROWID + "=" + tv1, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
this is the error I get now.
02-07 12:14:16.120: E/AndroidRuntime(2713): Caused by: android.database.sqlite.SQLiteException: near “@405dcd48”: syntax error: , while compiling: SELECT DISTINCT _id, name, nicbaseml, nicdrops, nicperct, pgml, pgdrops, pgperct, vgml, vgdrops, vgperct, wapml, wapdrops, wapperct, flv1name, flv1ml, flv1drops, flv1perct, flv2name, flv2ml, flv2drops, flv2perct, flv3name, flv3ml, flv3drops, flv3perct, flv4name, flv4ml, flv4drops, flv4perct, dropsml, amount, finalnic, bpg, bpg, basenic FROM recipes WHERE _id=android.widget.TextView@405dcd48
hmmm stuck on this one. Where is the error @405dcd48?
Here is the solution. It took many hours (2 days) to figure this out and then it was a dhooo! hand to the face moment. But never the less, here is the solution for others that have the same issue. In your declaration for populating the fields (in this case fetch(row).
Do this:
You will get the error as above and then a null pointer exception. This can be fixed by declaring your fields –>(txtbox1= (TextView) findViewById(R.id.textView22);.
Your database manager needs to be configured for a String.
Like this:
Now you can retrieve the data from the row using a textview or editview value equal to the row id of the data you are looking for.