This code places a Elementary list widgets on a window, along with some buttons trigerring actions on it (though its A\-P\-I).

It covers most of elm\-\_\-list\-\_\-item functions.

On our {\ttfamily main} function, we are adding a default list with 3 items. We are only setting their labels (second parameter of function elm\-\_\-list\-\_\-item\-\_\-append)\-:  
\begin{DoxyCodeInclude}
   li = elm_list_add(win);
   evas\_object\_size\_hint\_weight\_set(li, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(li, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm_box_pack_end(bx, li);

   elm_list_item_append(li, \textcolor{stringliteral}{"Item 0"}, NULL, NULL, NULL, NULL);
   elm_list_item_append(li, \textcolor{stringliteral}{"Item 1"}, NULL, NULL, NULL, NULL);
   elm_list_item_append(li, \textcolor{stringliteral}{"Item 2"}, NULL, NULL, NULL, NULL);

\end{DoxyCodeInclude}


Next we are adding lots of buttons, each one for a callback function that will realize a task covering part of list items A\-P\-I. Lets check the first one\-: 
\begin{DoxyCodeInclude}
   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Prepend item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_prepend\_cb, li);
   elm_box_pack_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, 0);
   evas\_object\_show(bt);

\end{DoxyCodeInclude}


We are labeling the button with a task description with elm\-\_\-object\-\_\-text\-\_\-set() and setting a callback function evas\-\_\-object\-\_\-smart\-\_\-callback\-\_\-add(). Each callback function will have the signature\-: {\ttfamily  static void \-\_\-task\-\_\-cb(void $\ast$data, Evas\-\_\-\-Object $\ast$obj, void $\ast$event\-\_\-info)} with the function name varying for each task.

Now let's cover all of them.

{\bfseries  Prepending an item\-: }  
\begin{DoxyCodeInclude}
\_prepend\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *list\_it;
   Evas\_Object *li = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   list\_it = elm_list_item_prepend(li, label, NULL, NULL, NULL, NULL);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\end{DoxyCodeInclude}


The item will be placed on the beginning of the list, i.\-e. it will be the first one.

The first parameter of \hyperlink{group__List_ga3a73d219a8eb4c034191ce3f2f196c99}{elm\-\_\-list\-\_\-item\-\_\-prepend()} is the list object, that we are receiving as data on our callback function. The second one is a label, the string that will be placed in the center of our item. As we don't wan't icons or callback functions, we can send N\-U\-L\-L as third, fourth, fifth and sixth parameters.

{\bfseries  Appending an item\-: }  
\begin{DoxyCodeInclude}
\_add\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *list\_it;
   Evas\_Object *li = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   list\_it = elm_list_item_append(li, label, NULL, NULL, NULL, NULL);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\end{DoxyCodeInclude}


Items included with append will be inserted inserted after the last one.

{\bfseries  Appending an item with icon\-: }  
\begin{DoxyCodeInclude}
\_add\_ic\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *list\_it;
   Evas\_Object *ic, *li = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   ic = elm_icon_add(li);
   elm_icon_standard_set(ic, \textcolor{stringliteral}{"home"});
   elm_image_resizable_set(ic, EINA\_FALSE, EINA\_FALSE);

   list\_it = elm_list_item_append(li, label, ic,  NULL, NULL, NULL);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     printf(\textcolor{stringliteral}{"Error adding item with icon\(\backslash\)n"});
\}

\end{DoxyCodeInclude}


If an icon is required, you can pass it as third parameter on our \hyperlink{group__List_ga80c4ef3e5b22f056615114b6e2d75cf9}{elm\-\_\-list\-\_\-item\-\_\-append()} function. It will be place on the left side of item's label. If an icon is wanted on the right side, it should be passed as fourth parameter.

For more details about how to create icons, look for elm\-\_\-icon examples \hyperlink{tutorial_icon}{Icon example}.

{\bfseries  Appending an item with callback function for selected\-: }  
\begin{DoxyCodeInclude}
\_sel\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *list\_it = event\_info;
   printf(\textcolor{stringliteral}{"Selected label: %s\(\backslash\)n"}, elm\_object\_item\_text\_get(list\_it));
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_add\_func\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *list\_it;
   Evas\_Object *li = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   list\_it = elm_list_item_append(li, label, NULL, NULL, \_sel\_cb, NULL);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\end{DoxyCodeInclude}


To set a callback function that will be called every time an item is selected, i.\-e., everytime the list stops with this item in center position, just pass the function as fifth parameter.

{\bfseries  Appending an item with callback function for selected with data\-: }  
\begin{DoxyCodeInclude}
\_sel\_data\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordtype}{char} *content = data;
   Elm_Object_Item *list\_it = event\_info;
   printf(\textcolor{stringliteral}{"Selected label: %s with data: %s\(\backslash\)n"},
          elm\_object\_item\_text\_get(list\_it), content);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_free\_data(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   free(data);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_add\_data\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *list\_it;
   Evas\_Object *li = data;
   \textcolor{keywordtype}{char} label[32];
   \textcolor{keywordtype}{char} *content = malloc(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}) * 32);

   snprintf(content, 32, \textcolor{stringliteral}{"Item content %i"}, counter);
   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   list\_it = elm_list_item_append(li, label, NULL, NULL, \_sel\_data\_cb, content);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     \{
        printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
        \textcolor{keywordflow}{return};
     \}
   elm_object_item_del_cb_set(list\_it, \_free\_data);
\}

\end{DoxyCodeInclude}


If the callback function request an extra data, it can be attached to our item passing a pointer for data as sixth parameter. Our function \-\_\-sel\-\_\-data\-\_\-cb will receive it as {\ttfamily  void $\ast$data }.

If you want to free this data, or handle that the way you need when the item is deleted, set a callback function for that, with \hyperlink{group__General_gadf971e78aa95cfd83fd3c3ce38ff8cd7}{elm\-\_\-object\-\_\-item\-\_\-del\-\_\-cb\-\_\-set()}.

As you can see we check if {\ttfamily it} is not {\ttfamily N\-U\-L\-L} after appending it. If an error happens, we won't try to set a function for it.

{\bfseries  Deleting an item\-: }  
\begin{DoxyCodeInclude}
\_del\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item;
   Evas\_Object *li = data;

   selected\_item = elm_list_selected_item_get(li);
   elm_object_item_del(selected\_item);
   elm_list_go(li);
\}

\end{DoxyCodeInclude}


To delete an item we simple need to call \hyperlink{group__General_ga6aac9c72588cd81c517b235c4b833c76}{elm\-\_\-object\-\_\-item\-\_\-del()} with a pointer for such item.

If you need, you can get selected item with \hyperlink{group__List_ga1416ffaedb7291babec621edfc0268d5}{elm\-\_\-list\-\_\-selected\-\_\-item\-\_\-get()}, that will return a pointer for it.

{\bfseries  Unselecting an item\-: }  
\begin{DoxyCodeInclude}
\_unselect\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item;
   Evas\_Object *li = data;

   selected\_item = elm_list_selected_item_get(li);
   elm_list_item_selected_set(selected\_item, EINA\_FALSE);
\}

\end{DoxyCodeInclude}


To select an item, you should call \hyperlink{group__List_gaf5ff690bf4c26dff24ad04522c26b79c}{elm\-\_\-list\-\_\-item\-\_\-selected\-\_\-set()} passing {\ttfamily E\-I\-N\-A\-\_\-\-T\-R\-U\-E}, and to unselect it, {\ttfamily E\-I\-N\-A\-\_\-\-F\-A\-L\-S\-E}.

{\bfseries  Printing all items\-: }  
\begin{DoxyCodeInclude}
\_print\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keyword}{const} Eina\_List *l, *items;
   Elm_Object_Item *list\_it;
   Evas\_Object *li = data;

   items = elm_list_items_get(li);
   EINA\_LIST\_FOREACH(items, l, list\_it)
     printf("%s\(\backslash\)n", elm\_object\_item\_text\_get(list\_it));
\}

\end{DoxyCodeInclude}


{\bfseries  Clearing the list\-: }  
\begin{DoxyCodeInclude}
\_clear\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *li = data;
   elm_list_clear(li);
\}

\end{DoxyCodeInclude}


{\bfseries  Selecting the next item\-: }  
\begin{DoxyCodeInclude}
\_select\_next\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item, *next\_item;
   Evas\_Object *li = data;

   selected\_item = elm_list_selected_item_get(li);
   \textcolor{keywordflow}{if} (!selected\_item) \textcolor{keywordflow}{return};

   next\_item = elm_list_item_next(selected\_item);
   \textcolor{keywordflow}{if} (next\_item)
     elm_list_item_selected_set(next\_item, EINA\_TRUE);
\}

\end{DoxyCodeInclude}


{\bfseries  Inserting after an item\-: }  
\begin{DoxyCodeInclude}
\_insert\_after\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item, *list\_it;
   Evas\_Object *li = data;
   \textcolor{keywordtype}{char} label[32];

   selected\_item = elm_list_selected_item_get(li);
   \textcolor{keywordflow}{if} (!selected\_item) \textcolor{keywordflow}{return};

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   list\_it = elm_list_item_insert_after(li, selected\_item, label, NULL, NULL,
                                        NULL, NULL);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\end{DoxyCodeInclude}


{\bfseries  Selecting the previous item\-: }  
\begin{DoxyCodeInclude}
\_select\_prev\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item, *prev\_item;
   Evas\_Object *li = data;

   selected\_item = elm_list_selected_item_get(li);
   \textcolor{keywordflow}{if} (!selected\_item) \textcolor{keywordflow}{return};

   prev\_item = elm_list_item_prev(selected\_item);
   \textcolor{keywordflow}{if} (prev\_item)
     elm_list_item_selected_set(prev\_item, EINA\_TRUE);
\}

\end{DoxyCodeInclude}


{\bfseries  Inserting before an item\-: }  
\begin{DoxyCodeInclude}
\_insert\_before\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item, *list\_it;
   Evas\_Object *li = data;
   \textcolor{keywordtype}{char} label[32];

   selected\_item = elm_list_selected_item_get(li);
   \textcolor{keywordflow}{if} (!selected\_item) \textcolor{keywordflow}{return};

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   list\_it = elm_list_item_insert_before(li, selected\_item, label, NULL, NULL,
                                         NULL, NULL);
   elm_list_go(li);
   \textcolor{keywordflow}{if} (!list\_it)
     printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\end{DoxyCodeInclude}


If a separator is required, just set an item as such\-:  
\begin{DoxyCodeInclude}
\_set\_separator\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item;
   Evas\_Object *li = data;

   selected\_item = elm_list_selected_item_get(li);
   \textcolor{keywordflow}{if} (!selected\_item) \textcolor{keywordflow}{return};
   elm_list_item_separator_set(selected\_item, EINA\_TRUE);
   elm_list_go(li);
\}

\end{DoxyCodeInclude}


Also an item can be disabled, and the user won't be allowed to (un)select it\-:  
\begin{DoxyCodeInclude}
\_disable\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_item;
   Evas\_Object *li = data;

   selected\_item = elm_list_selected_item_get(li);
   \textcolor{keywordflow}{if} (!selected\_item) \textcolor{keywordflow}{return};
   elm_object_item_disabled_set(selected\_item, EINA\_TRUE);
\}

\end{DoxyCodeInclude}


See the full \hyperlink{list_example_03_8c-example}{list\-\_\-example\-\_\-03.c} code, whose window should look like this picture\-:

 
\begin{DoxyImage}
\includegraphics{screenshots/list_example_03}
\caption{width=}
\end{DoxyImage}
 