I have a database and I would like to use it as data source for MultiAutoCompleteTextView. Is it possible utilize SimpleCursorAdapter in MultiAutoCompleteTextView?
this is code
Cursor cursor = db.query(TABLE_NAME, COLUMN, null, null, null, null, null);
mAdapter = new SimpleCursorAdapter(context,android.R.layout.simple_list_item_1, cursor,new String[]{"name"},new int[]{android.R.id.text1},0);
multiText.setAdapter(mAdapter);
Related
I have a database in my app, which I fill with data and an ID.
Then I request the database with the ID's I want:
Cursor cursor = contentResolver.query(uriPath, null, "ID = ?", new String[]{id1, id2, etc.}, null);
This retrieves me a cursor with all requested ID's .
How can I retrieve all objects in my UriPath ?
Just enter the Uri and leave the rest null
Cursor cursor = contentResolver.query(uriPath, null, null, null, null);
cursor = getContentResolver().query(GroceryItemProvider.ITEM_URI, projection, id+"="+GroceryItemTable.LIST_ID, null, null);
adapter= new SimpleCursorAdapter(this, R.layout.list_row, cursor, from, to , 0);
adapter.swapCursor(cursor);
This creates a list with the entire table rather than the cursor I pass with custom values, is that the default behaviour??
Do you mean you are getting all columns of data or all rows of data? If you are getting all columns, then please mention the value of variable projection. If you are getting all rows, then you can limit rows by providing the last argument to getContentResolver().query() method like:-
cursor = getContentResolver().query(GroceryItemProvider.ITEM_URI, projection, id+"="+GroceryItemTable.LIST_ID, null, "id limit 10");
I'm trying to search data on database based on 2 conditions (entryId=rowId & category=cat_id) like below
Cursor mCursor = db.query(true, "favorite", new String[] {"_id", "entry"}, "entryId="+ rowId + "& category="+cat_id, null, null, null, null, null);
Its not working. But when I try to do it using only one condition like below then it works well.
Cursor mCursor = db.query(true, "favorite", new String[] {"_id", "entry"}, "entryId="+ rowId, null, null, null, null, null);
Can you help me telling how can I run this query with multiple conditions?
In SQLite & is different from AND, simply use:
Cursor mCursor = db.query(true, "favorite", new String[] {"_id", "entry"},
"entryId="+ rowId + " AND category="+cat_id, null, null, null, null, null);
// Change & to AND... here: ^^^
I've an cursor that fills up my ListView in Android.
My code of cursor:
Cursor cursor = sqliteDatabase.query("ProductosTratamientos", null,
"codigoproducto <> '70027, 70029, 70024'", null, null, null, null);
It is not working. It continues filling the list with these values: 70027, 70029, 70024.
What am I doing wrong?
Thanks.
Instead of using <>, you need to use NOT IN which offers look-up with in a set of values. So try changing your query to something like:
Cursor cursor = sqliteDatabase.query("ProductosTratamientos", null,
"codigoproducto NOT IN (70027, 70029, 70024)", null, null, null, null);
Try this code:
Cursor cursor = sqliteDatabase.query("ProductosTratamientos", null,
"codigoproducto <> ? AND codigoproducto <> ? AND codigoproducto <> ?',
new String[]{"70027", "70029", "70024"},
null, null, null);
I have an Activity which goes through the normal procedures.
databaseHelper = new AppDatabaseHelper(this ); //openOrCreateDatabase(Constants.NAME, 1, null);
database = databaseHelper.getWritableDatabase();
// select columns[] from table order by sentdate desc
cursor = database.query(AppDatabaseHelper.MAIL_TABLE, columns, null, null, null, null, AppDatabaseHelper.C_MAIL_SENTDATE + " DESC");
// Does the displaying work //
cursorAdapter = new SimpleCursorAdapter(this, R.layout.mail_element, cursor, columns, columnsMap);
lv.setAdapter( cursorAdapter );
My problem is when the list gets refreshed, the dataset observer does not fire, and executing this code from a timer to ensure it is working causes all elements in the listview to become greyed out, or 50ish% invisible.
Log.d(Constants.TAG, "MailActivity > List changed!");
CursorAdapter.notifyDataSetChanged();
cursor = database.query(AppDatabaseHelper.MAIL_TABLE, columns, null, null, null, null, AppDatabaseHelper.C_MAIL_SENTDATE + " DESC");;
cursorAdapter = new SimpleCursorAdapter(context, R.layout.mail_element, cursor, columns, columnsMap);
lv.setAdapter( cursorAdapter );
Does anyone have an idea why these elements are turning grey when the list is updated? When I exit the activity and re-open it, it shows up fine again.
Solved, I had to change the cursor, instead of re-doing the adapter!
Log.d(Constants.TAG, "MailActivity > List changed!");
cursorAdapter.notifyDataSetChanged();
cursor = database.query(AppDatabaseHelper.MAIL_TABLE, columns, null, null, null, null, AppDatabaseHelper.C_MAIL_SENTDATE + " DESC");;
cursorAdapter.changeCursor( cursor );
lv.setAdapter( cursorAdapter );