再会!他在google 的文章上做了所有事情,但使用 ActionbarSherlock 及其实现 SearchView,但请求不会发送到 SearchActivity。你们中的任何人都可以知道可能是什么问题。只有当您按下键盘上的“输入”按钮时才会发送请求,我想让它类似于“实时搜索”,一旦开始输入,立即进行搜索。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.ex.Interface"
android:versionCode="45"
android:versionName="2.2.1b"
android:installLocation="auto"
>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:hardwareAccelerated="true"
android:theme="@style/Theme.Sherlock.Light.Custom"
>
<!-- enable the search dialog to send searches to SearchableActivity -->
<meta-data android:name="android.app.default_searchable"
android:value=".SearchActivity"/>
<activity
android:name=".SearchActivity"
android:screenOrientation="portrait"
android:parentActivityName=".MainFragmentActivity"
android:launchMode="singleTop"
>
<!-- This intent-filter identifies this activity as "searchable" -->
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!-- This metadata entry provides further configuration details for searches -->
<!-- that are handled by this activity. -->
<meta-data
android:name="android.app.searchable"
android:resource="@xml/search_config" />
</activity>
<activity
android:name=".MainFragmentActivity"
android:screenOrientation="portrait"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
MainFragmentActivity 中的板条箱菜单
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getSupportMenuInflater().inflate(R.menu.serch_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.search_menu).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
return true;
}
SearchActivity.java
public class SearchActivity extends CustomMenuFragmentActivity
{
@Override
public void onCreate(Bundle save)
{
super.onCreate(save);
setContentView(R.layout.search_page);
handleIntent(getIntent());
}
private void handleIntent(Intent intent)
{
if (Intent.ACTION_SEARCH.equals(intent.getAction()))
{
String query = intent.getStringExtra(SearchManager.QUERY);
goSearch(query);
}
}
@Override
public void onNewIntent(Intent intent)
{
setIntent(intent);
handleIntent(intent);
}
private void goSearch(final String s)
{}
}