我正在尝试实现片段。Fragment
正在创建,但问题是它里面的视图是空的,并且显示了一个空白屏幕。当我第一次运行它时,会显示视图,但在重新加载时,它的视图变为空并显示一个空白屏幕。不知道是什么问题。
这是我的代码....
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....");
}