我有一个简单的搜索小部件,我很难在我的应用程序中实现自定义搜索建议功能。
关于“构建建议表”的 Google Api 文档的文档记录确实很差。到目前为止,我已经设法让我的“SearchContentProvider”工作,它返回建议,但是当我在下拉列表中输入时,我只得到“空白”字段而没有文本。
有人可以建议我如何构建建议表吗?我应该在哪里实施“SUGGEST_COLUMN_TEXT_1”以便格式化并获得我的建议?
SearchContentProvider.java:
package com.exploreca.tourfinder;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.util.Log;
public class SearchContentProvider extends ContentProvider {
SQLiteOpenHelper dbhelper;
SQLiteDatabase database;
Cursor cursor;
private String LOGTAG;
@Override
public int delete(Uri arg0, String arg1, String[] arg2) {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getType(Uri arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public Uri insert(Uri arg0, ContentValues arg1) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean onCreate() {
// TODO Auto-generated method stub
return false;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
//instantieting the datasouce
dbhelper = new ToursDBOpenHelper(getContext());
database = dbhelper.getReadableDatabase();
Log.i(LOGTAG, "Selection Args: " + selectionArgs[0] + "\n " + "selection is: " + selection);
cursor = database.query(ToursDBOpenHelper.TABLE_TOURS, null,
selection, selectionArgs, null, null, null);
Log.i(LOGTAG, "Returned" + cursor.getCount() + "rows");
if (cursor.getCount() > 0){
while(cursor.moveToNext()){
cursor.getColumnIndex(cursor.getString(cursor.getColumnIndex(ToursDBOpenHelper.COLUMN_CITY)));
Log.i(LOGTAG, "Cursor is" + cursor);
}
}
return cursor;
}
@Override
public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
// TODO Auto-generated method stub
return 0;
}
}