Problem Filtering a SimpleCursorAdapter

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Problem Filtering a SimpleCursorAdapter

Postby Parakoos » Sat Feb 14, 2009 11:02 am

I want to display all contacts with a phone number in a list. I got the data, it is displayed in the list but my problem is that I can't get the text filter functionality to work. E.g. when the user types 'fre' it should filter out all entries not containing 'fre'.

This is what I've got in the ListActivity.onCreate()

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Cursor c = this.getContentResolver().query(People.CONTENT_URI,
  3.  
  4.                 new String[] { People._ID, People.DISPLAY_NAME },
  5.  
  6.                 People.PRIMARY_PHONE_ID + " IS NOT NULL",
  7.  
  8.                 null,
  9.  
  10.                 People.DISPLAY_NAME + " asc");
  11.  
  12. this.startManagingCursor(c);
  13.  
  14.  
  15.  
  16. SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
  17.  
  18.                 android.R.layout.simple_list_item_1,
  19.  
  20.                 c,
  21.  
  22.                 new String[] { People.DISPLAY_NAME },
  23.  
  24.                 new int[] { android.R.id.text1 });
  25.  
  26. adapter.setStringConversionColumn(adapter.getCursor().getColumnIndex(People.DISPLAY_NAME));
  27.  
  28. adapter.bindView(getListView(), this, c);
  29.  
  30. setListAdapter(adapter);
  31.  
  32. this.getListView().setTextFilterEnabled(true);
  33.  
  34.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
Parakoos
Freshman
Freshman
 
Posts: 6
Joined: Wed Feb 04, 2009 9:23 am

Top

Postby MrSnowflake » Sun Feb 15, 2009 9:16 am

*This is a database problem and has nothing to do with Views or anything. MOVED*

I think you should do something like:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. this.getContentResolver().query(People.CONTENT_URI,
  2.  
  3.           new String[] { People._ID, People.DISPLAY_NAME },
  4.  
  5.           People.PRIMARY_PHONE_ID + " IS NOT NULL AND "+People.NAME+" LIKE ",
  6.  
  7.           new String[]{"fre"},
  8.  
  9.           People.DISPLAY_NAME + " asc");
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
Or you could try using REGEXP with a regular expression.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby Parakoos » Sun Feb 15, 2009 10:45 am

No no no, you misunderstand my question. I am fine with how I am retrieving the data from the database. My questioning is in regard to how, in the ListView, I can activate the Text Filtering. Like in the Contacts application, when I start typing in a name, say 'Mart' the list of contacts is filtered down to say 'Martin' and 'Martina'. The application doesn't re-query the database with every single characer typed. This is a pure ListView feature to hide unrelated entries. The dataset remains the same.
Parakoos
Freshman
Freshman
 
Posts: 6
Joined: Wed Feb 04, 2009 9:23 am

Postby MrSnowflake » Sun Feb 15, 2009 11:14 am

Oh, sorry, mis understood you indeed.

Well, to allow filtering... I have no idea :). I would have implemented in the Adapter instead of using setFilterText() :).

Which means, you can use filtering without the setFilterText() and this would probably be a lot more flexible, though requires more attention from you, and you can also filter on non visible data.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 6 guests