I’m trying to manipulate the output of an SQLite query so into two parts – KEY_DATE and KEY_ROWID + KEY_TYPE. Here’s the code without the KEY_TYPE bit:
DataBaseAdapter db = new DataBaseAdapter(this);
db.open();
// get last test date
int whichItem = 1;
int upDown = 1; // use 1 for descending ordering
Cursor mCursor = db.getLogType(whichItem, upDown);
String[] columns = new String[] {DataBaseAdapter.KEY_DATE, DataBaseAdapter.KEY_ROWID};
startManagingCursor(mCursor);
ListAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_expandable_list_item_2, mCursor, columns, new int[] {android.R.id.text1, android.R.id.text2}){
public boolean areAllItemsEnabled(){
return false;
}
public boolean isEnabled(int position){
return false;
}
};
setListAdapter(adapter);
db.close();
It works fine, but when I replace:
String[] columns = new String[] {DataBaseAdapter.KEY_DATE, DataBaseAdapter.KEY_ROWID};
with:
String[] columns = new String[] {DataBaseAdapter.KEY_DATE, DataBaseAdapter.KEY_ROWID + DataBaseAdapter.KEY_TYPE};
it doesn’t work.
All help much appreciated!
Okay so I found a simpler answer. The problem was really with the concatenation. I was trying to do it in
String[] columns...but actually what I needed to do was to concatenate at as part of theSELECTquery and use an alias. Hence I changed theString[] columnsto include the column alias nameKEY_ROWID_TYPEas follows:And the query is then:
And of course I defined the
KEY_ROWID_TYPEtoo.Thanks to everyone for your help.