Android 未重新加载的片段

Android 未重新加载的片段,android,dynamic,android-fragments,reload,Android,Dynamic,Android Fragments,Reload,我正在尝试实现片段。正在创建片段,但问题是其中的视图为空,并显示一个空白屏幕。当我第一次运行它时,会显示视图,但在重新加载时,它的视图会变为null,并显示一个空白屏幕。不知道是什么问题 这是我的密码 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View r

我正在尝试实现片段。正在创建
片段
,但问题是其中的视图为空,并显示一个空白屏幕。当我第一次运行它时,会显示视图,但在重新加载时,它的视图会变为null,并显示一个空白屏幕。不知道是什么问题

这是我的密码

   public View onCreateView(LayoutInflater inflater, ViewGroup container,
                        Bundle savedInstanceState) {
                View root = inflater
                                .inflate(R.layout.winedescription, container, false);
                tvTitle = (TextView) root.findViewById(R.id.tvWineDescriptionTitle);
                tvDescription = (TextView) root
                                .findViewById(R.id.tvWineDescriptionDescription);
                tvWineName = (TextView) root
                                .findViewById(R.id.tvWineDescriptionWineName);
                tvWineType = (TextView) root.findViewById(R.id.tvWineDescriptionType);
                tvWinePrice = (TextView) root.findViewById(R.id.tvWineDescriptionPrice);
                btnSelect = (Button) root.findViewById(R.id.btnWineDescriptionSelect);
                imgWine = (ImageView) root.findViewById(R.id.ivWineImage);
                setDescription(position); 
                btnSelect.setOnClickListener(this);
                return root;
        }
我的父活动是一个适配器

public class WineFragmentPagerAdapter extends FragmentPagerAdapter {

        public static ArrayList<WineSubCategoryNameListModel> itemData = new ArrayList<WineSubCategoryNameListModel>();
        private int size = 0;

        public WineFragmentPagerAdapter(FragmentManager fm,
                        ArrayList<WineSubCategoryNameListModel> wineSubCategory) {
                super(fm);
                try {
                        itemData.clear();
                        if (wineSubCategory != null) {
                                for (int i = 0; i < wineSubCategory.size(); i++) {
                                        itemData.add(wineSubCategory.get(i));
                                }
                                size = itemData.size();
                        }
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }

        @Override
        public int getCount() {
                return size;
        }

        @Override
        public Fragment getItem(int position) {
                Log.d("wine", "Fragment Created");
                FragmentWineView f = FragmentWineView.newInstance();
                // f.setWineList(itemData);
                f.setPosition(position);
                return f;
        }
}




if (llWinePager.getChildCount() == 0) {
                    LayoutInflater infSelectTypeLayout = (LayoutInflater)     getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    wineDescriptionView = (LinearLayout) infSelectTypeLayout.inflate(
                                    R.layout.winedescriptionpager, null);
                    viewPage = (ViewPager) wineDescriptionView
                                    .findViewById(R.id.viewPager);
                    btnBackWineDescriptionView = (Button) wineDescriptionView
                                    .findViewById(R.id.btnBackWineDescriptionView);

                    WineFragmentPagerAdapter adapter = new WineFragmentPagerAdapter(
                                    getSupportFragmentManager(), wineSubCategory.get(0)
                                                    .getWineSubCategoryNameList());

                    viewPage.setAdapter(adapter);
                    viewPage.setOnPageChangeListener(WineMenu.this);
                    displayImage(subCategoryId);
                    llWinePager.addView(wineDescriptionView);
                    btnBackWineDescriptionView.setOnClickListener(this);
                    Log.d("wine", ".WineMenu .....IF....");
            } else {
                    WineFragmentPagerAdapter adapter = new WineFragmentPagerAdapter(
                                    getSupportFragmentManager(), wineSubCategory.get(0)
                                                    .getWineSubCategoryNameList());
                    viewPage.setAdapter(adapter);
                    displayImage(subCategoryId);
                    Log.d("wine", ".WineMenu .....Else....");
            }
公共类WineFragmentPagerAdapter扩展了FragmentPagerAdapter{
public static ArrayList itemData=new ArrayList();
私有整数大小=0;
公共葡萄酒碎片页面雷达(碎片管理器fm,
ArrayList(子类别){
超级(fm);
试一试{
itemData.clear();
如果(wineSubCategory!=null){
对于(int i=0;i
首先为extends FragmentActivity定义父类,然后在内部定义anyClass extends Fragment,然后此代码实现并检查

public class DemoFragment extends Fragment {

        public ConatactFragment() {
            // defult constructor
        }
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.YOUR_LAYOUT,container,false);
            return view;
        }

    }

显示片段的代码。尤其是
onCreateView
method使用onCreateView片段查看我编辑的代码。还要共享包含此片段的父活动。@user1508383否这不是您的父活动。这是一个适配器。初始化此适配器的活动是父级。请分享。