android利用数据库实现搜索联想功能
2010-05-26 02:13:00 来源:WEB开发网在res的xml文件夹下创建searchable.xml
< ?xml version="1.0" encoding="utf-8"? >
< searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/search_label"
android:searchSuggestAuthority="search"
android:searchSuggestIntentAction="android.intent.action.VIEW"
>
< /searchable >
结果返回:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = this.getIntent();
setContentView(R.layout.main);
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
SearchUtil.Word theWord = SearchUtil.getInstance().getMatches(
intent.getDataString().trim().toLowerCase()).get(0);
launchWord(theWord);
finish();
} else {
Button button = (Button) findViewById(R.id.button);
button.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
onSearchRequested();
return false;
}
});
}
}
private void launchWord(SearchUtil.Word pavilion) {
Intent next = new Intent();
next.setClass(this, ResultActivty.class);
Bundle bundle = new Bundle();
bundle.putString("word", pavilion.word);
next.putExtras(bundle);
next.putExtras(bundle);
startActivity(next);
}
其中联想的列表还可以实现自定义的列表,需要进一步细化。
更多精彩
赞助商链接