Я не могу найти решение, пожалуйста, помогите
Инструменты:
public class VentasActivity extends ActionBarActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks, android.support.v7.widget.SearchView.OnQueryTextListener
где возвращает null:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
getMenuInflater().inflate(R.menu.sales, menu);
restoreActionBar();
// HERE RETURNS NULL
searchView = (SearchView) menu.findItem(R.id.action_product_search).getActionView();
if (searchView != null) {
final Menu menu_block = menu;
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
// collapse the view ?
menu_block.findItem(R.id.action_product_search).collapseActionView();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
// search goes here !!
// listAdapter.getFilter().filter(query);
return false;
}
});
Log.i("sales module", "SearchView OK");
} else
Log.i("sales module", "SearchView is null");
return true;
}
return super.onCreateOptionsMenu(menu);
}
и sales.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_product_search"
android:title="@string/action_search"
android:icon="@drawable/ic_action_search"
app:showAsAction="always|collapseActionView"
android:actionViewClass="android.widget.SearchView" />
Большое спасибо!
ОБНОВЛЕНО: код restoreActionBar()
public void restoreActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}