歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android中Creating a Searchable Activity

Android中Creating a Searchable Activity

日期:2017/3/1 11:08:03   编辑:Linux編程

1.在<intent-filter>中用ACTION SEARCH聲明這個Activity。

2.用<meta-data>來指定searchable configuration。

例如:

<application ... >
<activity Android:name=".SearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
...
</application>

執行查詢:

當你的activity啟動時,通過下面的代碼來獲得查詢:

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);

// Get the intent, verify the action and get the query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}

doMySearch(query)是你自己的函數,用來完成查詢的具體工作。

Copyright © Linux教程網 All Rights Reserved