美好的一天! 他做了一切article from google,但用ActionbarSherlock和它的實現SearchView,但請求沒有發送到SearchActivity。 你們中的任何人都可以知道可能是什麼問題。只有當您按下鍵盤上的「enter」按鈕纔會發送請求,並且我希望使其工作類似於「實時搜索」,一旦開始進入,立即開始搜索。在MainFragmentActivity如何使用ActionBarSherlock進行搜索對話框(不搜索)
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>
裝箱菜單
@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)
{}
}