<ol>
and unordered <ul>
lists.
To create a list using jQuery Mobile ListView, specify the data-role="listview"
in a <ol>
or <ul>
element. And list the items using <li>
inside <ol>
or <ul>
container by specifying a link inside each list item <li>
to make it tappable.
Eg:
[html]
<ol data-role="listview">
<li><a href="#">Item1</a></li>
<li><a href="#">Item2</a></li>
</ol>
<ul data-role="listview">
<li><a href="#">Item1</a></li>
<li><a href="#">Item2</a></li>
</ul>
[/html]
To apply rounded corners and some margin to the lists, use the data-inset="true"
attribute.
Eg:
[html]
<ul data-role="listview" data-inset="true">[/html]
By default, list item links will turn into a button automatically. (no need for ui-class="btn" or data-role="button") data-role="list-divider"
to the element <li>
.
Eg:
[html]
<ol data-role="listview" data-inset="true">
<li data-role="list-divider">Operating Systems</li>
<li><a href="#">Android</a></li>
<li><a href="#">BlackBerry</a></li>
<li><a href="#">Iphone</a></li>
<li><a href="#">Windows</a></li>
</ol>
[/html]
With the attribute data-autodividers="true"
, jQuery Mobile can add respective dividers automatically to get alphabetically arranged list(for example dictionaries). The attribute is added on the <ol>
or <ul>
element.
The attribute data-autodividers="true"
creates dividers with first letters of the item's text which are of uppercase.
Eg:
[html]
<ul data-role="listview" data-autodividers="true">
<li data-role="list-divider">Social Networks</li>
<li><a href="https://www.facebook.com">Facebook</a></li>
<li><a href="https://www.twitter.com">Twitter</a></li>
<li><a href="https://www.google.com">Google</a></li>
<li><a href="https://www.instagram.com">Instagram</a></li>
</ul>
[/html] data-icon
to change this icon on the <li>
element.
Eg:
[html]
<ul data-role="listview">
<li><a href="#">Default -> right arrow</a></li>
<li data-icon="plus"><a href="#">Icon "plus"</a></li>
<li data-icon="delete"><a href="#">Icon "delete"</a></li>
<li data-icon="location"><a href="#">Icon "location"</a></li>
<li data-icon="false"><a href="#">false to remove icon</a></li>
</ul>
[/html] <img>
with a class of "ui-li-icon"
inside the link, to add a standard 16x16px icon to list, .
Eg:
[html]
<ul data-role="listview">
<li><a href="#"><img src="images\ic_launcher.png" class="ui-li-icon">Android</a></li>
</ul>
[/html] <img>
as the first child element in the list item (with no class name).
The image is scaled to 80x80px
automatically by jQuery Mobile.
Eg:
[html]
<ul data-role="listview">
<li>
<a href="#"><img src="images\ic_launcher.png">
<h2>Android</h2>
<p>Android is a mobile operating system based on Linux kernel</p>
</a>
</li>
</ul>
[/html] <li>
. The second link is placed on the right side of the list automatically with a arrow-icon facing right side. And the text inside the link (if any) is shown when hovered over the icon by the user.
Eg:
[html]
<ul data-role="listview">
<li>
<a href="#"><img src="images\logo.png"></a>
<a href="#">SPLessons</a>
</li>
</ul>
[/html] <span>
, with class "ui-li-count"
and add a number to add count bubbles, .
Eg:
[html]
<ul data-role="listview">
<li><a href="#">Inbox<span class="ui-li-count">250</span></a></li>
<li><a href="#">Sent<span class="ui-li-count">432</span></a></li>
<li><a href="#">Draft<span class="ui-li-count">2</span></a></li>
</ul>
[/html]