0

フラグメントを実装しようとしています。はFragment作成されていますが、問題はその中のビューが null であり、空白の画面が表示されることです。初めて実行するとビューが表示されますが、リロードするとビューが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;
        }

My Parent Activity アダプターです。

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....");
            }
4

1 に答える 1

0

まず最初に、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;
        }

    }
于 2012-12-07T12:00:32.460 に答える