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
10
votes
1 answer

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.getHeight() == 0 That's becuause the subView's…
Elad Benda
  • 35,076
  • 87
  • 265
  • 471
10
votes
3 answers

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 latitude. I want to highlight a textview when…
sascha
  • 265
  • 2
  • 4
  • 13
10
votes
2 answers

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 suggests I do something like surround with my…
Adam Johns
  • 35,397
  • 25
  • 123
  • 176
10
votes
3 answers

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 ? public class MobileArrayAdapter extends…
user2609157
9
votes
2 answers

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.android.support:support-v4:22.1.0' or higher. I…
Ragaisis
  • 2,700
  • 1
  • 26
  • 41
9
votes
2 answers

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:
happyhuman
  • 1,541
  • 1
  • 16
  • 30
9
votes
5 answers

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|orientation|screenSize" in my activity…
Sergio76
  • 3,835
  • 16
  • 61
  • 88
9
votes
1 answer

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:
gordonwd
  • 4,537
  • 9
  • 37
  • 53
9
votes
1 answer

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, int position) { LayoutInflater inflater =…
Wesley
  • 1,808
  • 5
  • 31
  • 46
9
votes
2 answers

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)context.getSystemService …
Andy
  • 10,553
  • 21
  • 75
  • 125
8
votes
4 answers

How to inflate a layout dynamically?

I have the following layout defined in XML:
Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556
8
votes
1 answer

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 isolate this error on API levels: I obtained an…
8
votes
2 answers

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 revision 24 that allow the inflation to occur on a…
MHogge
  • 5,408
  • 15
  • 61
  • 104
8
votes
3 answers

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-10387/com.example.rh.newsapp E/AndroidRuntime:…
roghayeh hosseini
  • 676
  • 1
  • 8
  • 21
8
votes
1 answer

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 do it programatically. My adapter code is as…
Reprator
  • 2,859
  • 2
  • 32
  • 55
1 2
3
81 82