I'm trying to preview a ListFragment
in the Graphical Layout Editor. As it has no fragment layout to preview, I simply created an xml with a ListView
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:
isInEditMode()
is true.Any idea?
EDIT: The fragment is a ListFragment
, but I can live with using a "temporary" listview.xml layout. What I want is a way to see a listview with my CustomListItemView
inside. In the fragment, I'll place them there with a custom adapter; in the layout editor I wish I could choose CustomListItemView
from Preview List Content menu.
I can't just use the custom item's layout as Preview List Content, because its root is a <merge>
(my custom item extends RelativeLayout
). This could be solved by changing for a moment <merge>
into <RelativeLayout>
. However, this custom item view changes depending on data, so I'd love to see a preview of the various states, by using the isInEditMode()
facility.
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 LinearLayout
.
I took a look, and it looks like the answer is that this isn't possible today, because of two bugs.
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.
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:
http://code.google.com/p/android/issues/detail?id=36838