Skip to content Skip to sidebar Skip to footer

Android: Fragments: Setcontentview Alternative

I'm trying to rewrite an existing project using fragments to port my application on tablet. I'm replacing activities with fragments. The problem is that I don't know what is the eq

Solution 1:

In the onCreateView() method you can return the view of your fragment as follows :

@OverridepublicViewonCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{ 
  return inflater.inflate(R.layout.ads_tab, container, false); 
}

Solution 2:

I'm not sure why you cannot use onCreateView. But here is what you can do.

Create LinearLayout object, save it as mRooLayout member field and return it from onCreateView. Here is how you can implement setContentView:

voidsetFragmentContentView(View view)
{
    LinearLayout.LayoutParamslayoutParams=newLinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, 
                                          ViewGroup.LayoutParams.FILL_PARENT);
    mRootLayout.removeAllViews();
    mRootLayout.addView(view, layoutParams);
}

Post a Comment for "Android: Fragments: Setcontentview Alternative"