How to text filter an Android ListView backed by a SimpleCursorAdapter?
I have a ListView that is backed by a SimpleCursorAdapter.
I'd like to be able to filter the list like you would a contacts list, just by typing, and I came across the textFilterEnabled()
Problem is, I couldn't see how to get it to work with a SimpleCursorAdapter.
Is this even possible?
If so, how is it done?
Asked by: Samantha638 | Posted: 24-01-2022
Answer 1
For a SimpleCursorAdapter cursor, you only need to use the setFilterQueryProvider, to run another query for your cursor, based on the constraint:
m_Adapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
Log.d(LOG_TAG, "runQuery constraint:"+constraint);
//uri, projection, and sortOrder might be the same as previous
//but you might want a new selection, based on your filter content (constraint)
Cursor cur = managedQuery(uri, projection, selection, selectionArgs, sortOrder);
return cur; //now your adapter will have the new filtered content
}
});
When a constraint is added (eg. by using a TextView) the adapter must be filtered:
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.d(LOG_TAG, "Filter:"+s);
if (m_slvAdapter!=null) {
m_Adapter.getFilter().filter(s);
}
}
Hope this helps. I will try to write a complete article , with source code the next few days.
Answered by: Wilson415 | Posted: 25-02-2022Answer 2
The setTextFilterEnabled()
method doesn't automatically implement filtering, as it doesn't know what in your Cursor
the text should be filtered against.
This android-developers thread has more details.
Actually, there was a good question asked the other day, which actually is very similar to your question; though it originally was asking how to handle filtering when there is no physical keyboard on a device:
Answered by: Daryl675 | Posted: 25-02-2022Answer 3
i found this article helpful http://androidcookbook.oreilly.com/Recipe.seam;jsessionid=CE37400B3E545937B70BE2E9F94E78BB?recipeId=404
basically, you setTextFilterEnabled(true)
on your listview, and you use setStringConversionColumn()
and setFilterQueryProvider()
on your SimpleCursorAdapter
.
Similar questions
Android: Using SimpleCursorAdapter to get Data from Database to ListView
I am programming an android app that should use a database to store data and read from it. Using this tutorial (on archive.org) I got the app to create a database and I'm able to create new entries, however, I don't know, how to read the database to get ...
java - How can we use an ID from database as Listview ID using SimpleCursorAdapter?
I am new to Android and started to work on databases and listview. I want to use subjectID as an ID of the listview I created. So that I can use that ID to query records from database when an item is tapped. I know this is asked many times but nothing seems to work on me. Thanks in advance for the help.
Part of the SQL: subjectID as _id
I have this piece of codes:
String[] dataColumns = { "...
android - How to auto load the large database values into listview using SimpleCursorAdapter
I have an app where I load database values into listview (multiple columns) using SimpleCursorAdapter. The problem is that the data is increasing everyday and the app clearly lags to load this entire data at one go into listview.
I have done a lot of Google for this, found many solutions (some using AsyncTasks and some using OnScrollListener events) but I am just unable to implement these ...
Android SimpleCursorAdapter and Database Update
I just started with Android development and love it so far. To get
some experience, I am writing a little todo application. In my
database I have a state for a todo item, represented as int. I use a
checkbox in a list view to represent this state. To bind the data to
the view, I use a subclass of SimpleCursorAdapter. I add an
onClickListener to the checkbox that updates the state in the database
for the used list item. The...
Android SimpleCursorAdapter Update when database updates
I have an application that uses SyncService and SyncAdapter. Within the application, I have an activity using a SimpleCursorAdapter. How do I go about updating the list when the database updates?
I have read that I should use adapter.changeCursor() or notifyDataSetChanged(), but where do I call it? And how would I know when the database is updated?
Also, I have heard that I could ...
Android SimpleCursorAdapter ID from Database
I'm having somewhat of an issue in an application I'm developing.
So, all my tables have _id fields for primary keys, and I use SimpleCursorAdapter to bind them to ListViews and Spinners.
What I wanted to know is how can I make the ListView or Spinner selected item have the same ID as the corresponding row?
The strange thing is that this works with the ContextMenu, which I am using straight of the NotePad example:
Android database simplecursoradapter error
I'm programming an android app.
This is my BDHelper class:
public class BD_Helper extends SQLiteOpenHelper{
private static final String BD_NOMBRE = "BD_PAED.db";
private static final int BD_VERSION = 1;
private static final String TABLA_AUDIT_NOMBRE = "audit";
private static final String TABLA_CONTROLES_NOMBRE = "controles";
private static final String crearAudit =
...
Android: Using SimpleCursorAdapter to get Data from Database to ListView
I am programming an android app that should use a database to store data and read from it. Using this tutorial (on archive.org) I got the app to create a database and I'm able to create new entries, however, I don't know, how to read the database to get ...
java - How can we use an ID from database as Listview ID using SimpleCursorAdapter?
I am new to Android and started to work on databases and listview. I want to use subjectID as an ID of the listview I created. So that I can use that ID to query records from database when an item is tapped. I know this is asked many times but nothing seems to work on me. Thanks in advance for the help.
Part of the SQL: subjectID as _id
I have this piece of codes:
String[] dataColumns = { "...
Android custom SimpleCursorAdapter with image from file with path in database
Gist: custom adapter gets file resource indirectly via filepath in database. Inefficiency / memory concerns. Your opinion requested.
References to all searches, related links, and things useful re topic are at post bottom.
Code below works, but several factors are of concern. Need some more experienced eyes on this please to suggest improvement or potential errors to avoid. App doesn't nee...
android - How to auto load the large database values into listview using SimpleCursorAdapter
I have an app where I load database values into listview (multiple columns) using SimpleCursorAdapter. The problem is that the data is increasing everyday and the app clearly lags to load this entire data at one go into listview.
I have done a lot of Google for this, found many solutions (some using AsyncTasks and some using OnScrollListener events) but I am just unable to implement these ...
sqlite - how to Refresh Database and then put the new data in a simplecursoradapter in android?
Mainactivity where I check the clicking of the refresh button
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Will close the drawer if the home button is pressed
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
case R.id.search:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
...
java - SimpleCursorAdapter with JSON data in database?
SimpleCursorAdapter is a quick way to pull data off a database and display it. However I also have JSON data stored in the database and want the Adapter to also display data inside the JSON.
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
ctx,
R.layout.list,
result,
new String[]{"name", "properties"}, //properties is a JSON string
new int[]{R.id.en...
android - Using a Spinner with a SimpleCursorAdapter
I have an activity which has a Spinner widget to display categories. Initially I was using an ArrayAdapter to populate the the spinner as in the following code
private static final String[] arrayCategories = {
"Business",
"Personal"
};
mCatSpinner = (Spinner) findViewById(R.id.thecategory);
ArrayAdapter<String> catAdapter = new ArrayAdapter<String>(this, R.layout.track_category_item, array...
how to set the simplecursoradapter to a listview in android?
i have to set the simpleCursorAdapter into a listView.
how can i achieve that?
thanks.
sqlite - Android: Filtering a SimpleCursorAdapter ListView
Right now, I'm running into issues trying to implement a FilterQueryProvider in my custom SimpleCursorAdapter, since I'm unsure of what to do in the FilterQueryProvider's runQuery function.
In other words, since the query that comprises my ListView basically gets the rowID, name, and a third column from my databases's table, I want to be able to filter the cursor based on the partial value of the name column.
...
android - Computation on db data then list them using either SimpleCursorAdapter or ArrayAdapter
I juststarted programming in android a few weeks ago, so I am not entirely sure how to deal with listing values. Please help me out!
I have some questions regarding displaying data sets from db in a list. Currently I have a cursor returned by my db points to a list of rows and I want display 2 columns values in a single row of the list. The row xml looks like this:
<TextView android:id="@+id/text1"
...
android - Impossible to close Cursor when setting to SimpleCursorAdapter
Im performing certain database operations after which I attach Cursor to the SimpleCursorAdapter for display List on my ListActivity. If I close the cursor in finally block (or anywhere after the code below), nothing is displayed in the list
SimpleCursorAdapter scAdapter = new SimpleCursorAdapter(this,
R.layout.list_row, cursor,
new String[] { Constants.KEY_TITLE }, new int[] { R.id.tex...
android - Jerky Scrolling when using SimpleCursorAdapter with ListView
I'm getting some very jerky scrolling while using the code below to
create a ListView from a Cursor. Is there something I'm doing wrong,
or any way to improve the performance of this ListView?
bookmarksListView = (ListView)findViewById(R.id.bookmarks_listview);
bookmarksDbCursor = bookmarkStore.getCursor();
startManagingCursor(bookmarksDbCursor);
...
android - SimpleCursorAdapter crashes within an Activity
I'm trying to create an activity with a list that uses a SimpleCursorAdapter, but it just won't work. I'm creating the cursor correctly because when I make it print out text, all the values are printed and I know there's nothing wrong with the SimpleCursorAdapter class because when I used it with the image content provider, it displayed correctly. However, when I try to put the two together, my ap...
Android SimpleCursorAdapter and Database Update
I just started with Android development and love it so far. To get
some experience, I am writing a little todo application. In my
database I have a state for a todo item, represented as int. I use a
checkbox in a list view to represent this state. To bind the data to
the view, I use a subclass of SimpleCursorAdapter. I add an
onClickListener to the checkbox that updates the state in the database
for the used list item. The...
sqlite - Android SimpleCursorAdapter / ListView issue
I have a problem displaying the results of an sql query into a ListView via SimpleCursorAdapter. This is my query:
String sql = "" +
"SELECT (Clients.firstname || \" \" || Clients.surname) AS client_name, " +
"Visits._id, " +
"Status.status, " +
"strftime('%H:%M',time(sql_start_date,'unixepoch')) as start_time, " +
"strftime('%H:%M',time(sql_end_date,'unixepoch')) as end...
java - onClick inside ListActivity using SimpleCursorAdapter
I've got a class that creates a list from a DB using SimpleCursorAdapter. I want to add an onClick event to each item in the list but I don't know where to place the code.
Any help?
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android