Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

lincoln bernard
lincoln bernard
74 Points

My Listview Activity is blank and no errors in the log cat or console

I have been building a simple list view app with a custom view, but when I run it in the emulator the activity is blank (the app does launch). There are no errors in the log cat or console and I have scoured through every line of code and I have no idea what I'm doing wrong. Please help me, here is the source:

Here's the source code to my app in git:

https://github.com/theduffster/beacon_portal

2 Answers

Jonathan Baker
Jonathan Baker
2,304 Points

Hi Lincoln,

I noticed that in your Activity's layout, the ListView's height is set to "wrap_content". While this may make sense in your head to do, it's actually a bad idea (not to mention most likely will not work). When you are asking the view to wrap it's content, it means it must measure the height of all it's children. In the case of a ListView, that would mean all the rows for all the items in your adapter. This is extremely expensive to do, and will most likely end up being too tall for your device's screen anyways.

The solution to this is to be more explicit about the ListView's height. You can do this by either telling it to match it's parent's height (with layout_height="match_parent"), or by telling it to fill the empty space within the parent LinearLayout using weights (layout_height="0dp", layout_weight="1").

Let us know if this doesn't make your ListView visible!

-- Jonathan

lincoln bernard
lincoln bernard
74 Points

Thank you so much, now it all makes sense! Worked like a charm