O código no qual estou trabalhando está usando a Toolbar
e inflando a menu
.
Aqui está o código
private Toolbar mToolbar;
mToolbar.inflateMenu(R.menu.chat_screen_menu);
setupMenu ();
private void setupMenu ()
{
mMenu = mToolbar.getMenu();
if (mMenu != null)
{
if (mChatPager != null && mChatPager.getCurrentItem() > 0)
{
mMenu.setGroupVisible(R.id.menu_group_chats, true);
mMenu.setGroupVisible(R.id.menu_group_contacts, false);
}
else
{
mMenu.setGroupVisible(R.id.menu_group_chats, false);
mMenu.setGroupVisible(R.id.menu_group_contacts, true);
mMenu.setGroupVisible(R.id.menu_group_otr_verified,false);
mMenu.setGroupVisible(R.id.menu_group_otr_unverified,false);
mMenu.setGroupVisible(R.id.menu_group_otr_off,false);
}
}
mToolbar.setOnMenuItemClickListener(new OnMenuItemClickListener ()
{
..........
}
}
Mas agora, eles exigem um Search
botão no tool_bar
. Consegui colocar, segui um guia aqui.
Quando tento escrever algo para pesquisar, o brinde que fiz para testar o listener
nunca mostrado. o que indica que listener
não está funcionando
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.chat_screen_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_menu_search));
final Toast toast = new Toast(mApp);
if (mSearchView != null )
{
mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
mSearchView.setIconifiedByDefault(false);
SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener()
{
public boolean onQueryTextChange(String newText)
{
mSearchString = newText;
//doFilterAsync(mSearchString);
toast.makeText(getApplicationContext(), "Test1", Toast.LENGTH_LONG).show();
return true;
}
public boolean onQueryTextSubmit(String query)
{
mSearchString = query;
//doFilterAsync(mSearchString);
toast.makeText(getApplicationContext(), "Test2", Toast.LENGTH_LONG).show();
return true;
}
};
mSearchView.setOnQueryTextListener(queryTextListener);
}
return true;
}
import android.support.v7.widget.SearchView