Answer the question
In order to leave comments, you need to log in
Why can onOptionsItemSelected nullify variables?
Good afternoon, I do not quite understand what my problem is, could you take a look at my code. If I click on a dynamic menu, then listAdapter = null, or if I get a listView
, then I have no control over it - I can't do anything with it, for example, make it INVISIBLE.
If I click on R.id.filter_everything: or others that have an id everything is ok.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
iDynamicToolbar.onChangeToolbar();
if (actionBar != null) {
subtitle = actionBar.getSubtitle();
}
if (viewGroup != null) {
if (viewGroup.findViewById(R.id.detailFragmentContainer) != null) {
menu.add(Menu.NONE, IDM_ZOOM, Menu.NONE, "Увеличить")
.setIcon(R.drawable.zoom).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
}
inflater.inflate(R.menu.goods_menu, menu);
SubMenu subMenu = menu.addSubMenu("Выбор склада");
Set<String> set = Remainder.loadScladName(getActivity());
int menuId = 1;
menuItemObjects = new ArrayList<>();
if (set != null) {
for (String nameSclad : set) {
if (!nameSclad.equals("")) {
menuItemObjects.add(new MenuItemObject(nameSclad, menuId, true));
subMenu.add(IDM_GET_SCLAD, menuId, Menu.NONE, nameSclad);
subMenu.setGroupCheckable(IDM_GET_SCLAD, true, false);
menuId++;
}
}
}
for (MenuItemObject itemObject : menuItemObjects) {
menu.findItem(itemObject.getId()).setChecked(true);
}
searchItem = menu.findItem(R.id.action_search);
menuItem = menu.findItem(R.id.action_menu);
filterEverything = menu.findItem(R.id.filter_everything);
filterRest = menu.findItem(R.id.filter_rest);
SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
searchView = (SearchView) searchItem.getActionView();
if (searchView != null) {
if (searchManager != null) {
searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
}
queryTextListener = new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
return true;
}
@Override
public boolean onQueryTextSubmit(String s) {
query = s;
startSearchGoods(modeRadio, mMLCategory, query, null);
return true;
}
};
searchView.setOnQueryTextListener(queryTextListener);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.d(TAG, String.valueOf("onOptionsItemSelected: " + getPrefsTypeLoad() +" "+ mGoodsAdapterLazy));
//обработка нажатия динамического меню
switch (item.getItemId()) {
case R.id.filter_everything:
item.setChecked(true);
modeRadio = RADIO_ALL;
if (getPrefsTypeLoad() == GoodsList.MODE_LIST && query == null) {
resetIndex();
listLazyGoods.clear();
initData(menuItemObjects);
} else {
EventBus.getDefault().post(new GoodsListEventFilter(RADIO_ALL));
startSearchGoods(RADIO_ALL, mMLCategory, query, menuItemObjects);
}
break;
case R.id.filter_rest:
item.setChecked(true);
modeRadio = RADIO_WITH_REST;
if (getPrefsTypeLoad() == GoodsList.MODE_LIST && query == null) {
resetIndex();
listLazyGoods.clear();
initData(menuItemObjects);
} else {
EventBus.getDefault().post(new GoodsListEventFilter(RADIO_WITH_REST));
startSearchGoods(RADIO_WITH_REST, mMLCategory, query, menuItemObjects);
}
break;
case IDM_ZOOM:
EventBus.getDefault().post(new GoodsListEventZoom());
break;
}
for (MenuItemObject itemObject : menuItemObjects) {
int itemId = itemObject.getId();
if (item.getItemId() == itemId) {
if (!item.isChecked()) {
if (getPrefsTypeLoad() == GoodsList.MODE_LIST) {
resetIndex();
listLazyGoods.clear();
item.setChecked(true);
itemObject.setChecked(true);
initData(menuItemObjects);
setSubtitle();
} else {
setSubtitle();
item.setChecked(true);
itemObject.setChecked(true);
startSearchGoods(modeRadio, mMLCategory, null, menuItemObjects);
setSubtitle();
}
} else {
if (getPrefsTypeLoad() == GoodsList.MODE_LIST) {
resetIndex();
listLazyGoods.clear();
item.setChecked(false);
itemObject.setChecked(false);
initData(menuItemObjects);
setSubtitle();
} else {
item.setChecked(false);
itemObject.setChecked(false);
startSearchGoods(modeRadio, mMLCategory, null, menuItemObjects);
setSubtitle();
}
}
}
}
return super.onOptionsItemSelected(item);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question