我有一個簡單的搜索小部件,我很難在我的應用程序中實現自定義搜索建議功能。空白/空白下拉,android自定義搜索建議
關於「Building a suggestion table」的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;
}
}
它是返回的建議光標的列 – pskink