Можем ли мы реализовать SeachView в Android 2.2 с помощью 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)