I have a search dialog which needs to be suggestion enabled from the database as shown here http://developer.android.com/images/search/search-suggest-custom.png.
My search dialog will be shown at the top, when i click an action bar menu item. When the user starts typing in some text, it should search the db and display suggestions accordingly. As of now, i have a search dialog, but when the user types in some text, no suggestions are displayed.
my content provider:
public class MyCustomSuggestionProvider extends ContentProvider {
SQLiteDatabase db;
SQLiteQueryBuilder qb;
String sqlTables = "countries";
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return 0;
}
@Override
public String getType(Uri uri) {
return null;
}
@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}
@Override
public boolean onCreate() {
return false;
}
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
MyDatabase myDB = new MyDatabase(getContext());
db = myDB.getReadableDatabase();
Cursor c = null;
if (selectionArgs != null && selectionArgs.length > 0
&& selectionArgs[0].length() > 0) {
qb = new SQLiteQueryBuilder();
String[] sqlSelect = { "name" };
qb.setTables(sqlTables)
c = qb.query(db, null, selection, selectionArgs, null, null,
null);
c.moveToFirst();
} else {
return null;
}
return c;
}
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
return 0;
}
}
my manifest:
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Visa" >
android:name="com.m7.visa.contentprovider.MyCustomSuggestionProvider"
android:authorities="com.m7.visa.contentprovider.MyCustomSuggestionProvider" >
android:name="com.m7.visa.MainActivity"
android:label="@string/app_name" >
android:name="android.app.searchable"
android:resource="@xml/searchable" />
my searchable configuration:
android:hint="hint..."
android:label="@string/app_name"
android:searchSuggestAuthority="com.m7.visa.contentprovider.MyCustomSuggestionProvider"
android:searchSuggestIntentAction="android.intent.action.VIEW"
android:searchSuggestSelection=" ?" >
any idea where am i going wrong?
.
stackoverflow.comm
No comments:
Post a Comment