Questions tagged [layout-inflater]

The layout-inflater tag refers to the Android LayoutInflater class which is used to build a view hierarchy from an xml layout file.

The LayoutInflater class will build a view hierarchy from the XML layout, taking care of instantiating the views and setting them with the attributes values present in that layout file. This class can't be used directly, instead a reference to a valid LayoutInflater object can be obtained by using one of the methods of the Activity class or by getting it from the system services.

The usage of the LayoutInflater is simple: just use one of the inflate() methods and provide it the id of the XML layout file (in the form of R.layout.layout_file) along with other desired parameters. More information can be found in the documentation of the class.

1229 questions
382
votes
15 answers

What does LayoutInflater in Android do?

What is the use of LayoutInflater in Android?
user386430
  • 4,837
  • 13
  • 41
  • 45
275
votes
7 answers

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…
hash
  • 5,336
  • 7
  • 36
  • 59
273
votes
12 answers

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…
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
242
votes
15 answers

How to inflate one view with a layout

I have a layout defined in XML. It contains also: I would like to inflate this RelativeView with other XML layout file. I…
Michal Dymel
  • 4,312
  • 3
  • 23
  • 32
216
votes
29 answers

How to change the Text color of Menu item in Android?

Can I change the background color of a Menu item in Android? Please let me know if anyone have any solution to this. The last option will be obviously to customize it but is there any way for changing the text color without customizing it.
sunil
  • 9,541
  • 18
  • 66
  • 88
210
votes
6 answers

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 =…
Lukap
  • 31,523
  • 64
  • 157
  • 244
205
votes
7 answers

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…
Kevin
  • 23,174
  • 26
  • 81
  • 111
142
votes
11 answers

"Avoid passing null as the view root" warning when inflating view for use by AlertDialog

I get the lint warning, Avoid passing null as the view root when inflating views with null as parent, like: LayoutInflater.from(context).inflate(R.layout.dialog_edit, null); However, the view is to be used as the content of an AlertDialog, using…
Randy Sugianto 'Yuku'
  • 71,383
  • 57
  • 178
  • 228
123
votes
21 answers

Android: Last line of textview cut off

I have a horizontal LinearLayout containing a TextView followed by a Spinner next to it. This LinearLayout is dynamically inflated multiple times in a fixed vertical LinearLayout contained within a RelativeLayout. The problem is that since I…
Rynardt
  • 5,547
  • 7
  • 31
  • 43
110
votes
14 answers

How to change the background color of the options menu?

I'm trying to change the default color for the options menu which is white: I want a black background for every item on the options menu. I've tried some shoots like android:itemBackground="#000000" on the item element within the menu element but it…
feragusper
  • 1,236
  • 2
  • 11
  • 8
107
votes
9 answers

How does the getView() method work when creating your own custom adapter?

My questions are: What is exactly the function of the LayoutInflater? Why do all the articles that I've read check if convertview is null or not first? What does it mean when it is null and what does it mean when it isn't? What is the parent…
GrowinMan
  • 4,891
  • 12
  • 41
  • 58
59
votes
2 answers

NPE while inflating layout (Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference)

I keep getting a java.lang.NullPointerException when I try to use ScrollView in an activity. The weird thing is that I've used the exact same Scrollview setup in other activities. And all of a sudden I'm getting errors. I've tried cleaning the…
57
votes
5 answers

Unconditional layout, inflation from view adapter: Should use View Holder pattern

I am getting following warning in eclipse: Unconditional layout inflation from view adapter: Should use View Holder pattern (use recycled view passed into this method as the second parameter) for smoother scrolling. on: convertView =…
TheDevMan
  • 5,914
  • 12
  • 74
  • 144
50
votes
9 answers

Problem inflating custom view for AlertDialog in DialogFragment

I'm trying to create a DialogFragment using a custom view in an AlertDialog. This view must be inflated from xml. In my DialogFragment class I have: @Override public Dialog onCreateDialog(Bundle savedInstanceState) { return new…
43
votes
3 answers

What should I pass for root when inflating a layout to use for a MenuItem's ActionView?

I have an ImageView that I attach to a MenuItem as its ActionView (the item appears in the ActionBar). The layout for this view comes from XML. I'm inflating it like so: ImageView actionView = (ImageView) layoutInflater.inflate( …
dlf
  • 9,045
  • 4
  • 32
  • 58
1
2 3
81 82