フラグメントを実装しようとしています。は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....");
}