bigstones bigstones - 1 year ago 63
Android Question

ListFragment or ListView preview in Layout Editor

I'm trying to preview a

in the Graphical Layout Editor. As it has no fragment layout to preview, I simply created an xml with a
inside, just to see how the items look, and set Preview List Content with one of the default item layouts, just to try.

The problems are:

  1. The list in the preview is empty, no matter what Preview List Content I choose; (I don't know what I was doing wrong, now it works)

  2. I want to preview my own custom list item View, not just a layout, because I'll be doing few things when
    is true.

Any idea?

EDIT: The fragment is a
, but I can live with using a "temporary" listview.xml layout. What I want is a way to see a listview with my
inside. In the fragment, I'll place them there with a custom adapter; in the layout editor I wish I could choose
from Preview List Content menu.

I can't just use the custom item's layout as Preview List Content, because its root is a
(my custom item extends
). This could be solved by changing for a moment
. However, this custom item view changes depending on data, so I'd love to see a preview of the various states, by using the

The best would be if it all could work without the temporary listview.xml layout, but this is becoming a feature request.

Right now I'm resorting to use a vertical

Answer Source

I took a look, and it looks like the answer is that this isn't possible today, because of two bugs.

  1. For some reason, ListView preview doesn't work if the ListView is the root element of the layout, rather than being embedded within the layout. The workaround for this is simple; just surround the ListView with some other layout such as a LinearLayout, setting you ListView's layout_width and layout_height to match_parent.

  2. For some reason, when a layout with a ListView along with a custom view is included into another layout, the custom list item layout isn't working. I know this used to work, so it must have broken at some point, probably when we switched from using comment-style metadata to the tools-namespace metadata to record which layout to use.

I've filed this issue to track the work:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download