I am trying to use a custom view group with cover flow. Instead of an XML layout or view , I am trying to load the view from fragment transaction. Here is the code I am trying to use here,
@Override
public View getCoverFlowItem(int i, View reuseableView, ViewGroup viewGroup) {
CustomViewGroup fancyView = null;
if (reuseableView != null) {
fancyView = (CustomViewGroup) reuseableView;
} else
{
fancyView = new CustomViewGroup(context);
fancyView.getFrameLayout().setId(i+10000);
fancyView.setLayoutParams(new FancyCoverFlow.LayoutParams(750, ViewGroup.LayoutParams.WRAP_CONTENT));
}
FragmentManager fragmentManager = manager;
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(fancyView.getFrameLayout().getId(), ItemFragment.init(i));
fragmentTransaction.commit();
return fancyView;
}
class CustomViewGroup extends LinearLayout {
// =============================================================================
// Child views
// =============================================================================
private FrameLayout frameLayout;
// =============================================================================
// Constructor
// =============================================================================
private CustomViewGroup(Context context) {
super(context);
this.setOrientation(VERTICAL);
this.frameLayout = new FrameLayout(context);
LinearLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
this.frameLayout.setLayoutParams(layoutParams);
this.addView(this.frameLayout);
}
// =============================================================================
// Getters
// =============================================================================
private FrameLayout getFrameLayout() {
return frameLayout;
}
}
For me the issue is the getView function is getting called infinite number of times for value i=0. But If I don't commit a fragment transaction it works normal(ie getting called only once for index 0)
Any clue on whats happening here?
Thanks