ChildView无形

时间:2013-08-12 14:47:30

标签: android fragment viewgroup

我这里有这段代码。如您所见,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);
        }
    }

0 个答案:

没有答案