我是Android应用程序开发的新手,我正在构建一个简单的歌曲书应用程序,在主页上显示列表视图,显示歌曲列表。单击歌曲将带您进入包含歌词的页面。
我正在使用Dreamweaver CC和Phonegap。这是一个非常简单的过程,我已经完成了一切。我只需要像大多数列表应用程序一样在列表的右侧添加一个按字母顺序排列的滚动条。
这是我的索引页面代码:
<div id="page" data-role="page">
<div data-role="header">
<h1>Song Book</h1>
</div>
<div data-role="content">
<ul data-role="listview">
<li data-role="list-divider" data-theme="c">A</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">B</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">C</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">D</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">E</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">F</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">G</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">H</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">I</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">J</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">K</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">L</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">M</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">N</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">O</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">P</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">Q</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">R</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">S</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">T</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">U</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">V</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">W</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">X</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">Y</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
<li data-role="list-divider" data-theme="c">Z</li>
<li><a href="#page2">A Common Love</a></li>
<li><a href="#page3">Song 2</a></li>
<li><a href="#page4">Song 3</a></li>
</ul>
</div>
我一直在网上看了几个小时没有,但我找不到一个好的解决方案我可以开始工作。我为字母表中的每个字母使用了一个列表分隔符。我可以设置滚动条以导航到每个列表分隔符吗?
将按字母顺序排列的滚动条添加到列表中的最佳方法是什么?
谢谢!
答案 0 :(得分:0)
可能,但我不知道这对于这样的小屏幕是否能够顺畅导航
HTML
<div data-role="page" id="list">
<div data-role="content">
<ul data-role="listview">
<li data-role="list-divider" id="a">A</li>
<li class="showDetails">
Adam Kinkaid
</li>
<li class="showDetails">Alex Wickerham</li>
<li class="showDetails">Avery Johnson</li>
<li data-role="list-divider" id="b">B</li>
<li class="showDetails">Bob Cabot</li>
<li data-role="list-divider" id="c">C</li>
<li class="showDetails">Caleb Booth</li>
<li class="showDetails">Christopher Adams</li>
<li class="showDetails">Culver James</li>
<li data-role="list-divider" id="d">D</li>
<li class="showDetails">David Walsh</li>
<li class="showDetails">Drake Alfred</li>
<li data-role="list-divider" id="e">E</li>
<li class="showDetails">Elizabeth Bacon</li>
<li class="showDetails">Emery Parker</li>
<li class="showDetails">Enid Voldon</li>
<li data-role="list-divider" id="f">F</li>
<li class="showDetails">Francis Wall</li>
<li data-role="list-divider" id="g">G</li>
<li class="showDetails">Graham Smith</li>
<li class="showDetails">Greta Peete</li>
<li data-role="list-divider" id="h">H</li>
<li class="showDetails">Harvey Walls</li>
<li data-role="list-divider" id="m">M</li>
<li class="showDetails">Mike Farnsworth</li>
<li class="showDetails">Murray Vanderbuilt</li>
<li data-role="list-divider" id="n">N</li>
<li class="showDetails">Nathan Williams</li>
<li data-role="list-divider" id="p">P</li>
<li class="showDetails">Paul Baker</li>
<li class="showDetails">Pete Mason</li>
<li data-role="list-divider" id="r">R</li>
<li class="showDetails">Rod Tarker</li>
<li data-role="list-divider" id="s">S</li>
<li class="showDetails">Sawyer Wakefield</li>
</ul>
<ul data-role="none" id="list-navigation">
<li>
<p id="list-1" class="scrollToSelected"><strong>1</strong></p>
<p id="list-2" class="scrollToSelected"><strong>2</strong></p>
<p id="list-3" class="scrollToSelected"><strong>3</strong></p>
<p id="list-a" class="scrollToSelected"><strong>A</strong></p>
<p id="list-b" class="scrollToSelected"><strong>B</strong></p>
<p id="list-c" class="scrollToSelected"><strong>C</strong></p>
<p id="list-d" class="scrollToSelected"><strong>D</strong></p>
<p id="list-e" class="scrollToSelected"><strong>E</strong></p>
<p id="list-f" class="scrollToSelected"><strong>F</strong></p>
<p id="list-g" class="scrollToSelected"><strong>G</strong></p>
<p id="list-h" class="scrollToSelected"><strong>H</strong></p>
<p id="list-i" class="scrollToSelected"><strong>I</strong></p>
<p id="list-j" class="scrollToSelected"><strong>J</strong></p>
<p id="list-k" class="scrollToSelected"><strong>K</strong></p>
<p id="list-l" class="scrollToSelected"><strong>L</strong></p>
<p id="list-m" class="scrollToSelected"><strong>M</strong></p>
<p id="list-n" class="scrollToSelected"><strong>N</strong></p>
<p id="list-o" class="scrollToSelected"><strong>O</strong></p>
<p id="list-p" class="scrollToSelected"><strong>P</strong></p>
<p id="list-q" class="scrollToSelected"><strong>Q</strong></p>
<p id="list-r" class="scrollToSelected"><strong>R</strong></p>
<p id="list-s" class="scrollToSelected"><strong>S</strong></p>
<p id="list-t" class="scrollToSelected"><strong>T</strong></p>
<p id="list-u" class="scrollToSelected"><strong>U</strong></p>
<p id="list-v" class="scrollToSelected"><strong>V</strong></p>
<p id="list-w" class="scrollToSelected"><strong>W</strong></p>
<p id="list-x" class="scrollToSelected"><strong>X</strong></p>
<p id="list-y" class="scrollToSelected"><strong>Y</strong></p>
<p id="list-z" class="scrollToSelected"><strong>Z</strong></p>
</li>
</ul>
</div>
</div>
<div data-role="page" id="details">
<div data-role="content">
<ul data-role="listview">
<li data-role="list-divider">Details</li>
<li><a href="#list" data-direction="reverse">List</a></li>
</ul>
<br />
<p>
Here are the details you were looking for
</p>
</div>
</div>
CSS
#list-navigation {
color:#696969;
position:absolute;
right:0px;
top:0px;
z-index:200;
}
JS
$('.scrollToSelected').bind('click', function() {
var view = $(this).attr('id');
var list = view.split('-');
var elem = $("#"+list[1]);
// not sure if this is offset or position
var position = elem.position();
var offset = elem.offset();
$.mobile.silentScroll(position.top);
});
$('.showDetails').bind('click', function() {
$.mobile.changePage( "#details", { transition: "slideup"} );
});
小提琴