I want to show or hide item in actionbar according to either their is text in the edit text or not
so I did the following
seachEditText =(EditText) rootView.findViewById(R.id.nounSearch);
seachEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
searchResult.Entities = new ArrayList<NounModel>();
_currentPage = 0;
categoryId = -1;
new GetNouns().execute();
return true;
}
else
{
getActivity().invalidateOptionsMenu();
}
return false;
}
});
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
if(seachEditText.getText().toString().length() > 0)
{
menu.findItem(R.id.action_search).setVisible(true);
}
else
{
menu.findItem(R.id.action_search).setVisible(false);
}
}
but the actionitem never appear
0 comments:
Post a Comment