Answer the question
In order to leave comments, you need to log in
Why can onOptionsItemSelected nullify fragment state?
Good afternoon. Here I do not understand what the problem is.
There is a LOAD_TYPE parameter (byte)0 or 1 that I pass in the fragment arguments.
if I originally created a fragment with LOAD_TYPE 1, then everything is ok too.
But it’s worth creating a fragment with type LOAD_TYPE 0, then for some reason 0 always comes to onOptionsItemSelected, even if I send 1. In onCreateView I get everything from the arguments as needed.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d(TAG, String.valueOf("onCreateView: " + this.loadGoodsTask_MODE +" || "+getArguments().getByte(EXTRA_GOODS_LIST)));
return inflater.inflate(R.layout.goods_list, container, false);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.d(TAG, String.valueOf("onOptionsItemSelected: " + this.loadGoodsTask_MODE +" || "+getArguments().getByte(EXTRA_GOODS_LIST)));
for (MenuItemObject itemObject : menuItemObjects) {
int itemId = itemObject.getId();
if (item.getItemId() == itemId) {
if (!item.isChecked()) {
if (loadGoodsTask_MODE == GoodsList.MODE_LIST) {
resetIndex();
listLazyGoods.clear();
item.setChecked(true);
itemObject.setChecked(true);
initData(menuItemObjects);
} else {
item.setChecked(true);
itemObject.setChecked(true);
startSearchGoods(modeRadio, mMLCategory, null, menuItemObjects);
}
} else {
if (loadGoodsTask_MODE == GoodsList.MODE_LIST) {
resetIndex();
listLazyGoods.clear();
item.setChecked(false);
itemObject.setChecked(false);
initData(menuItemObjects);
} else {
item.setChecked(false);
itemObject.setChecked(false);
startSearchGoods(modeRadio, mMLCategory, null, menuItemObjects);
}
}
}
}
setSubtitle();
searchView.setOnQueryTextListener(queryTextListener);
return true;
}
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