Mike Szczys · Jun 16, 2013 at 11:30 pm

Why Devs Should Avoid ‘Null’ when Inflating Layouts

We’ve all done it at one point or another. You are hammering out some code and need one aspect of a method call to work so you just put null in for the rest of the parameters instead of actually researching how they work. I’ve actually done the very thing Dave Smith writes of in his article about inflating layouts. The second argument in a LayoutInflater inflate method calls for ‘ViewGroup root.’ I just slap ‘null’ in there and go about my business, none the wiser. There’s nothing wrong with that; it pulls the XML file passed as the first parameter into your layout so that it can be displayed on the screen. You could go years without having a real problem with it. But when it does it bite you at some point down the road, you’re going to pay a big time penalty trying to figure out what is going wrong.

Dave did a great job writing his article explaining how a LayoutInflater works. The reason the inflater is looking for a ViewGroup is to inherit any styling that may have been set at a higher lever. He shows an example of this using a ListView that should have a fixed height specified by the theme. If you specify null, it has no context from which to inherit the values and results in the smallest height possible. He goes on to assume that the developer would then create a second XML specification to fix the problem, and I think he’s spot on with that prediction. This breaks the concept of themes and makes the code much harder to maintain. He does mention an exception when inflating for an AlertDiaog, but this is a moot point because the inflater will basically ignore the ViewGroup parameter when specified for a dialog.

[via Reddit || Photo Source]


_________
Want something on the XDA Portal? Send us a tip!
Emil Kako · Feb 26, 2015 at 12:30 pm · 1 comment

What Bugs You Most About Google’s Play Store?

Google announced today that it will be bringing ads to the Play Store, and while that will surely annoy the majority of us, it isn't the only thing that sucks about the Play Store. From the lack of clear communication with developers to ridiculous restrictions, there are a handful of very annoying things about Google's approach. Let us know what bugs you the most about the Play Store.

DISCUSS
Mario Tomás Serrafero · Feb 26, 2015 at 11:32 am · 1 comment

Watches: Luxurious Frivolity vs. Humble Practicality

Smartwatches still have a lot of growing up to do. Not too long ago the latest Canalys figures revealed a rather disappointing outcome for 2014, something we covered with the ultimate conclusion that, once again, smartwatches had no year. The direction of smartwatches is unclear to even the biggest OEMs, and with every new option there seems to be polarizing dissonances from what people and OEMs want and what they both think they want. We've documented many of the reasons as to...

XDA NEWS
Mathew Brack · Feb 26, 2015 at 10:28 am · no comments

Do ISPs Abuse Their Power?

Every day, the majority of us use the internet through several different internet service providers, but what we may not think about whilst using this service is how much control these companies have over our experience. AT&T recently launched their rival to the Google Fiber service and subsequently looked for a way to further monetize on their offering. For an extra $29 on top of the $70 monthly charge, you can buy your privacy back from them. Otherwise expect online adverts...

XDA NEWS
Share This