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
41
votes
3 answers

Plugins architecture for an Android app?

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 become really large, with many features that only a…
Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
35
votes
4 answers

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 = LayoutInflater.from(context); a third one (when I am in an…
Hamzeh Soboh
  • 7,572
  • 5
  • 43
  • 54
27
votes
3 answers

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); but after execution of the above the layout will…
Matteo B.
  • 3,906
  • 2
  • 29
  • 43
27
votes
1 answer

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…
user782104
  • 13,233
  • 55
  • 172
  • 312
23
votes
2 answers

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(inflater, parent, false); Are there any…
21
votes
2 answers

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 at…
Gaurav
  • 667
  • 2
  • 13
  • 28
19
votes
3 answers

Change background color of android menu

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 page: http://tinyurl.com/342dgn3. The author…
rciovati
  • 27,603
  • 6
  • 82
  • 101
18
votes
2 answers

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 is as flat as posible with ConstraintLayout. But…
17
votes
3 answers

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, LayoutParams.WRAP_CONTENT); …
Lukap
  • 31,523
  • 64
  • 157
  • 244
16
votes
4 answers

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 dynamically I need a feed and their comments.For…
14
votes
2 answers

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 shows Fragment B. My problem is when I am in…
Chris
  • 379
  • 1
  • 6
  • 19
12
votes
4 answers

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 BaseAdapter { Context context; …
Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
12
votes
4 answers

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 iterator = commentInformations.iterator(); while(iterator.hasNext()) { i++; …
11
votes
2 answers

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 documentation. From sources I've understood that if…
Kirill
  • 7,580
  • 6
  • 44
  • 95
10
votes
1 answer

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) { super(context, attrs); LayoutInflater…
soren.qvist
  • 7,376
  • 14
  • 62
  • 91
1
2
3
81 82