List widget example

This code places a single Elementary list widgets on a window, just to exemplify the more simple and common use case: a list will be created and populated with a few items.

To keep it simple, we won't show how to customize the list, for this check List widget example. Also, we won't focus on items management on this example. For an example about this subject, check List - Items management.

To add a list widget.

li = elm_list_add(win);
elm_list_add
Evas_Object * elm_list_add(Evas_Object *parent)
Add a new list widget to the given parent Elementary (container) object.
Definition: elm_list.c:2513

We are just adding the list, so as you can see, defaults for it are:

- Items are displayed vertically.
- Only one item can be selected.
- The list doesn't bounce.

To add items, we are just appending it on a loop, using function elm_list_item_append(), that will be better explained on items management example.

static const char *lbl[] =
{
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
for (i = 0; i < sizeof(lbl) / sizeof(lbl[0]); i++)
elm_list_item_append(li, lbl[i], NULL, NULL, NULL, NULL);
elm_list_item_append
Elm_Widget_Item * elm_list_item_append(Elm_List *obj, const char *label, Efl_Canvas_Object *icon, Efl_Canvas_Object *end, Evas_Smart_Cb func, const void *data)
Append a new item to the list object.
Definition: elm_list_eo.legacy.c:129

After we just want to show the list. But first we need to start the widget. It was done this way to improve widget's performance. So, always remember that:

Warning
  Call elm_list_go before showing the object
  elm_list_go(li);
  elm_list_go
  void elm_list_go(Elm_List *obj)
  Starts the list.
  Definition: elm_list_eo.legacy.c:111
  evas_object_show(win);
  evas_object_show
  EVAS_API void evas_object_show(Evas_Object *eo_obj)
  Makes the given Evas object visible.
  Definition: evas_object_main.c:1814
  See the full list_example_01.c code, whose window should look like this picture: