我这里有这段代码。如您所见, noItemBox 是在适配器为空或 null 时显示的消息。然而,问题是每次我切换选项卡并取回片段时,noItemBox 都是可见的。为什么会这样?谁能帮我解决这个问题,非常感谢。谢谢。
if (adapter == null || (adapter != null && adapter.isEmpty())) {
if (noItemBox == null) {
noItemBox = new NoItemBox(getActivity());
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
int marginTop = getResources().getDisplayMetrics().heightPixels / 5;
params.setMargins(0, marginTop, 0, 0);
rootView.addView(noItemBox, params);
// check root view address
}
noItemBox.setVisibility(View.VISIBLE);
if(launchMode == Constants.LAUNCH_MODE_LOCATOR || launchMode == Constants.LAUNCH_MODE_ORDER_CART_Add) {
noItemBox.setDesc(getString(R.string.error_msg_cant_find_location));
} else {
noItemBox.setTitle(getString(R.string.no_saved_rest));
noItemBox.setImage(getResources().getDrawable(R.drawable.dashboard_savedstores));
}
// storeList.setVisibility(View.GONE);
} else {
storeList.setVisibility(View.VISIBLE);
if (noItemBox != null ) {
noItemBox.setVisibility(View.GONE);
}
}