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.
layout-inflater
1,230
questions
384
votes
15
answers
337k
views
What does LayoutInflater in Android do?
What is the use of LayoutInflater in Android?
277
votes
12
answers
83k
views
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 ...
276
votes
7
answers
106k
views
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 ...
242
votes
15
answers
466k
views
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 ...
218
votes
29
answers
318k
views
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 ...
210
votes
6
answers
167k
views
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 ...
205
votes
7
answers
141k
views
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,...
142
votes
11
answers
52k
views
"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 ...
122
votes
21
answers
87k
views
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 ...
110
votes
15
answers
189k
views
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" ...
107
votes
9
answers
136k
views
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 ...
59
votes
2
answers
17k
views
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 ...
57
votes
5
answers
37k
views
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 ...
50
votes
9
answers
70k
views
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 ...
43
votes
3
answers
31k
views
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 = (...
41
votes
3
answers
15k
views
Plugins architecture for an Android app? [closed]
THIS QUESTION HAS MOVED TO https://softwarerecs.stackexchange.com/questions/27841/plugins-architecture-for-an-android-app
I want to implement a plugin system for an Open Source app, because it has ...
35
votes
4
answers
26k
views
What is the correct way to get layout inflater in Android?
There is a way to get layoutInflater:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
and another way is:
LayoutInflater inflater = ...
28
votes
1
answer
16k
views
What is the difference between setContentView and LayoutInflater?
I am creating a tabs list with several fragments.
I have noticed that, in the main activity, I used setContentView to get the layout xml and use findViewById to get the corresponding UI element ...
27
votes
3
answers
33k
views
Create View-Object from XML file in android
I only want to get an object from a xml layout file without having to implement it into the current layout.
I know the way with
LayoutInflater.from(context).inflate(R.layout.myfile, myparent, true);
...
23
votes
2
answers
10k
views
Android Databinding DatabindingUtil vs binding class
I was wondering what is the difference between the following:
binding = DataBindingUtil.inflate(inflater, R.layout.drawer_item_primary, parent, false);
vs
binding = DrawerItemPrimaryBinding.inflate(...
21
votes
2
answers
3k
views
Android Stringblock.get NullPointer Exception on Lollipop
I am getting a crash on Android Lolipop.
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.content.res.StringBlock.get(int)' on a null object reference ...
19
votes
3
answers
94k
views
Change background color of android menu [duplicate]
I'm trying to change the standard light grey to a light green. Seems that there is not a simple way to do this (through Android Themes, for example) but I have found a workaround as explained at this ...
18
votes
2
answers
2k
views
What does VerifyClass inside Systrace mean?
I´m looking at the systrace generated by my app and I have identified a frame that is taking too long.
This is caused by a RecyclerView's onCreateViewHolder when inflating my item view. The item view ...
17
votes
3
answers
7k
views
It inflate the view without the margin
I have this code
View item = View.inflate(context, R.layout.item_layout, null);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
...
16
votes
4
answers
26k
views
How to prevent items from getting duplicated when scrolling recycler view
I have created a row inside recycler view and inside that I have inflated two rows or more but when I scroll the items are getting used again.
I am not getting where to recycle view or remove them ...
14
votes
2
answers
31k
views
Android force Fragment to rebuild View
I have a simple app that has two fragments and when in landscape mode, both fragments are shown side by side and in portrait I show Fragment A and then if they select an option, start an Activity that ...
13
votes
4
answers
2k
views
Setting text on multiple inflated EditTexts causes all to be populated with same text after rotation
I am inflating a few EditTexts and adding them to a LinearLayout:
private void setupCommentViews(){
int i = 0;
Iterator<CommentInformation> iterator = commentInformations.iterator();...
12
votes
4
answers
11k
views
Create a Generic Base Adapter?
I am interested in creating a generic BaseAdapter which will apply to any ListView having any list_item . And it will set the item_row for the list_view.
public class GenericAdapter extends ...
11
votes
2
answers
1k
views
What's the difference between LayoutInflater's Factory and Factory2
There is two public interfaces:
LayoutInflater.Factory and LayoutInflater.Factory2 in android sdk, but official documentation can't say something helpfull about this interfaces, even LayoutInflater ...
11
votes
1
answer
468
views
Robolectric returns 0 height for a view with wrap content height
I have an android customView which I want to test.
Few of the tests simulate a scroll of N dps when N is a subView height.
I run the tests with robolectric, but I always get in runtime that subView....
10
votes
3
answers
33k
views
Why to use Inflater in listview
I always had ambiguity on why we need to use inflater in android, Why are they used in ListView for custom layouts (like below)?
What is an Inflater ?
What is the advantage of using Inflater ?
...
10
votes
1
answer
8k
views
Android layout previewer throws error when adding custom LinearLayout
I've defined a custom ViewGroup that extends the functionality of a LinearLayout:
public class TestLayout extends LinearLayout {
public TestLayout(Context context, AttributeSet attrs) {
...
10
votes
3
answers
18k
views
findViewById in non-Activity class
Still being relatively new to this I'm having issues in finding a view in a non-activity class MyLocation which I'm using in my activity class MainActivity. I'm using MyLocation to get longitude and ...
10
votes
2
answers
2k
views
Is it recommended to check view for null with every findViewById call?
When inflating an element with findViewById, Android Studio always warns me that my inflated view may return null
View v = inflater.inflate(R.layout.fragment_photo_gallery, container, false);
and ...
9
votes
5
answers
25k
views
fragments and onConfigurationChanged
I'm trying to do something I do with activities, but within a fragment.
What I do is using activities:
First stop the activity restarts when rotating the device
android:configChanges="keyboardHidden|...
9
votes
1
answer
9k
views
Unable to set layout width, height and weight of inflated view in XML in Android
I am developing an Android app. In my app, I need to inflate list of views dynamically. I added them and working. The problem is with setting the width and height of layout. Now I will demonstrate my ...
9
votes
1
answer
4k
views
Unexpected LayoutParams with an inflated LinearLayout
I have an XML definition for a view that I am adding to a larger container view with addChild. It's based on a LinearLayout and looks basically like this:
<LinearLayout xmlns:android="http://...
9
votes
2
answers
2k
views
What is the difference between calling LayoutInflater directly and not?
I went through some tutorials, and in the Android Doc, it says not to access LayoutInflater directly when instantiating it. Example from the google Doc:
LayoutInflater inflater = (LayoutInflater)...
9
votes
1
answer
16k
views
Inflate new layout xml for each view - instantiateItem in PagerAdapter
So basically i want to populate the pages inside ViewPager with separate XML layouts for each view position. I'm currently doing this by
@Override
public Object instantiateItem(View container, ...
9
votes
2
answers
3k
views
Custom View children are null after inflating the view in Android
I am working on an Android app. I have a custom view and layout as follows:
<com.hello.view.card.inner.SimpleCardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="...
9
votes
2
answers
1k
views
LayoutInflater.Factory onCreateView is not called with 22.1+ support library
Main problem that my LayoutInflater.Factory (code example below) calls onCreateView and works fine with 'com.android.support:support-v4:22.0.0'. But onCreateView is not called when i moved to 'com....
8
votes
4
answers
36k
views
How to inflate a layout dynamically?
I have the following layout defined in XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="...
8
votes
1
answer
8k
views
ViewStub raises error while inflating more than one layouts conditionally
In my app, I am having a spinner, and a ViewStub, depending upon the user item selection from spinner, I have to inflate different layouts and show the inflated layout below the spinner. When my app ...
8
votes
3
answers
17k
views
Error inflating class ImageView - android.view.InflateException: Binary XML file line #10: Error inflating class ImageView
I'm designing an app that has a xml file for the list items (list_item.xml),
and an adapter for the listView (NewsAdapter.java).
My app encounters this error when running:
09-22 20:26:29.595 10387-...
8
votes
2
answers
3k
views
Use AsyncLayoutInflater with DataBinding
I currently inflate most of my layouts using the DataBindingUtil.inflate(inflater, layoutId, parent, attachToParent) method.
But I saw that their is an AsyncLayoutInflater since Support Library ...
8
votes
1
answer
13k
views
Create or inflate views programmatically in a RecyclerView OnCreateViewHolder
Basically I wanted to create a layout or inflate a layout programatically with a RecyclerView, but was unable to do so. As I know how to do with xml by inflating it, but out of curiosity I wanted to ...
8
votes
2
answers
10k
views
How to get context in getView of adapter for listview
I have three questions:
I am using getApplicationContext unlike all the examples I have seen which just say context. How do I get the context here? Or is the application context fine?
Is there any ...
8
votes
1
answer
2k
views
Inflating TextView throwing noSuchMethodException on method addFontWeightStyle() during inflate process
Update: I've changed the title to remove the indication that ExoPlayer has anything to do with what is going on as I've managed to duplicate this without it being used at all.
I decided to try and ...
8
votes
3
answers
3k
views
Dynamically added views disappear on orientation in Android
I have created the views to be added in dynamically to a layout from a button click, but when I rotate the device landscape, the views disappear. Could someone please look at my code and explain how ...
8
votes
2
answers
5k
views
how do you use the second parameter in the inflate method of the LayoutInflater class, Android
The inflate method of the LayoutInflater abstract class has as the second parameter of the inflate method that takes ViewGroup root. From the documentation, it is mentioned as an "Optional view to be ...