Customizing List View Control Characteristics

Now you're ready to customize the rather bland (especially for a game menu) default ListView control with a custom divider and selection graphics. A ListView control has several parts—a header, the list of items, and a footer. By default, the ListView control displays no header or footer.

Did you Know?

Adding a Custom Divider

A ListView divider is displayed between each ListView item. The divider attribute can be either a color or a drawable graphic resource. If a color is specified, then a horizontal line (whose thickness is configurable) will be displayed between items in the list. If a drawable graphic resource is used, the graphic will appear between items. By default, no divider is displayed above the first list item nor below the last.

If you have a screen with only a ListView control, consider using the ListActivity class, which simplifies ListView management.

Adding a Custom Selector

A ListView selector indicates which list item is currently selected within the list. The ListView selector is controlled by the listSelector attribute. The default selector of a ListView control is a bright orange band.

TVy It Yourself

To add a divider to the ListView control, simply open the menu.xml layout file and change the ListView control's divider attribute to the @drawable/divider graphic resource (a squiggly yellow line) you added earlier.

Now, add a custom selector to the ListView control. To do this, simply open the menu.xml layout file and change the ListView control's listSelector attribute to the @drawable/textured graphic resource (a textured orange halo) you added earlier.

If you make the changes to the ListView divider and selector and re-launch the Been There, Done That! application in the emulator, the main menu screen should look as shown in Figure 8.4.

FIGURE 8.4

The Been There, Done That! main menu screen with a customized ListView control.

0 0

Post a comment