onCreateOptionsMenu inside Fragments

I have placed setHasOptionsMenu(true) inside onCreateView, but I still can’t call onCreateOptionsMenu inside fragments. @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setHasOptionsMenu(true); return inflater.inflate(R.layout.facesheet, container, false); } Below is my onCreateOptionsMenu code. @Override public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) { getSupportMenuInflater().inflate(R.menu.layout, menu); return (super.onCreateOptionsMenu(menu)); } The error message I get: The method onCreateOptionsMenu(Menu) of … Read more

Call getLayoutInflater() in places not in activity

What does need to be imported or how can I call the Layout inflater in places other than activity? public static void method(Context context){ //this doesn’t work the getLayoutInflater method could not be found LayoutInflater inflater = getLayoutInflater(); // this also doesn’t work LayoutInflater inflater = context.getLayoutInflater(); } I am able to call getLayoutInflater only … Read more

How to inflate one view with a layout

I have a layout defined in XML. It contains also: <RelativeLayout android:id=”@+id/item” android:layout_width=”fill_parent” android:layout_height=”wrap_content” /> I would like to inflate this RelativeView with other XML layout file. I may use different layouts depending on a situation. How should I do it? I was trying different variations of RelativeLayout item = (RelativeLayout) findViewById(R.id.item); item.inflate(…) But none … Read more

What does the LayoutInflater attachToRoot parameter mean?

The LayoutInflater.inflate documentation isn’t exactly clear to me about the purpose of the attachToRoot parameter. attachToRoot: whether the inflated hierarchy should be attached to the root parameter? If false, root is only used to create the correct subclass of LayoutParams for the root view in the XML. Could someone please explain in more detail, specifically … Read more

Avoid passing null as the view root (need to resolve layout parameters on the inflated layout’s root element)

Passing null for root studio gives me this warning: Avoid passing null as the view root (need to resolve layout parameters on the inflated layout’s root element) It is showing a null value in getGroupView. Please help. public class ExpandableListAdapter extends BaseExpandableListAdapter { private Context _context; private List<String> _listDataHeader; // header titles // child data … Read more