Hi,
I am having problems filtering my ListView, that gets its data from a
SimpleCursorAdapter. There are a number of threads around about this,
including <a href="http://groups.google.co.uk/group/android-developers/
browse_thread/thread/5d19c5dd3f28307d#"> here</a>, <a href="http://
groups.google.co.uk/group/android-developers/browse_thread/thread/
7ed8593be568d86e">here</a>, and <a href="http://groups.google.co.uk/
group/android-developers/browse_thread/thread/22b015b031a13bb2"> here
</a> but a lot of them seem to be referring to Autocomplete views,
whereas I want to filter my ListView - I'm sure the concepts are the
same but I can't get it to work. My code is below, I would appreciate
any pointers, thanks.
ListView list=(ListView)findViewById(R.id.rail);
final DbAdapter dbAdapt = new DbAdapter(this);
dbAdapt.open();
Cursor mStationsCursor_rail = dbAdapt.query_rail_stations();
startManagingCursor(mStationsCursor_rail);
String[] from_rail = new String[]{DbAdapter.KEY_NAME};
int[] to_rail = new int[] {android.R.id.text1};
SimpleCursorAdapter rail_adapt = new
SimpleCursorAdapter(this,android.R.layout.simple_list_item_1,
mStationsCursor_rail, from_rail, to_rail);
rail_adapt.setFilterQueryProvider(new FilterQueryProvider()
{
//@Override
public Cursor runQuery(CharSequence constraint) {
String filter = constraint.toString().toUpperCase() +
"%";
Cursor mStationsCursor_rail_filter =
dbAdapt.query_rail_stations(filter); //this is an overloaded method in
another class that returns the filtered cursor correctly
return mStationsCursor_rail_filter;
}
});
list.setAdapter(rail_adapt);
// this is hard-coded at the moment for testing, but clearly I will
want to create this from an EditText, but that // should be
comparatively easy
Cursor newcursor =
rail_adapt.getFilterQueryProvider().runQuery("ch");
rail_adapt.setStringConversionColumn(1);
newcursor.moveToFirst();
rail_adapt.convertToString(newcursor);
Many thanks
Stephen Knox
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en