我們能否使用ActionbarSherlock Android 2.2中實現SeachView。的Android ActionbarSherlock搜索查看
我使用下面的代碼,它工作正常在3.0,但2.2
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//getMenuInflater().inflate(R.menu.main_menu, menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
// set up a listener for the refresh item
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
// Do something
System.out.println("onQueryTextChange----------");
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
// Do something
System.out.println("onQueryTextSubmit----------");
return true;
}
};
searchView.setOnQueryTextListener(queryTextListener);
return true;
}
我收到以下錯誤在2.2
at 01-23 17:31:53.230: W/MenuInflater(20214): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
01-23 17:31:53.230: W/MenuInflater(20214): at com.actionbarsherlock.internal.view.menu.MenuInflaterImpl$MenuState.newInstance(MenuInflaterImpl.java:533)
01-23 17:31:53.230: W/MenuInflater(20214): at com.actionbarsherlock.internal.view.menu.MenuInflaterImpl$MenuState.setItem(MenuInflaterImpl.java:497)
01-23 17:31:53.230: W/MenuInflater(20214): at com.actionbarsherlock.internal.view.menu.MenuInflaterImpl$MenuState.addItem(MenuInflaterImpl.java:515)
01-23 17:31:53.230: W/MenuInflater(20214): at com.actionbarsherlock.internal.view.menu.MenuInflaterImpl.parseMenu(MenuInflaterImpl.java:238)
01-23 17:31:53.230: W/MenuInflater(20214): at com.actionbarsherlock.internal.view.menu.MenuInflaterImpl.inflate(MenuInflaterImpl.java:164)
01-23 17:31:53.230: W/MenuInflater(20214): at com.actionbarsherlock.sample.styledactionbar.MainActivity.onCreateOptionsMenu(MainActivity.java:99)
01-23 17:31:53.230: W/MenuInflater(20214): at android.support.v4.app.FragmentActivity.dispatchCreateOptionsMenu(FragmentActivity.java:601)
01-23 17:31:53.230: W/MenuInflater(20214): at android.support.v4.app.FragmentActivity.invalidateOptionsMenu(FragmentActivity.java:706)
請看看[這個答案](http://stackoverflow.com/questions/14991980/actionbarsherlock-searchview-setonquerytextlistener/15050518#15050518)。我沒有使用低於3.0的版本進行測試。 –